I wish to drag an item from a gridview to a picturebox. At the position of the 'drop' in the picturebox a circle is to be drawn at that point.
My problem is that with the drop event in the picturebox I can't get the x & y position in the picturebox..
It seems that when the mouse drag enters the picturebox the normal values of mouse.x & .y aren't available.
Any help would be appreciated.
Drawingarea drag&drop
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Drawingarea drag&drop
Last edited by bill-lancaster on Thursday 19th November 2020 1:52pm, edited 1 time in total.
- BruceSteers
- Posts: 1574
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Picturebox drag&drop
Did you set Picturebox1.Tracking to true?
I think that how you activate mouse data on controls. i could be wrong though
I think that how you activate mouse data on controls. i could be wrong though
If at first you don't succeed , try doing something differently.
BruceS
BruceS
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: Picturebox drag&drop
Thanks, yes, tracking and drop set to true.
I'm making a small project to better show the problem.
I'm making a small project to better show the problem.
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: Picturebox drag&drop
This code shows the problem.
An item selected from the gridview and dropped in the drawingarea draws the circle in the wrong place
An item selected from the gridview and dropped in the drawingarea draws the circle in the wrong place
Code: Select all
' Gambas class file v3.15.2
Private Const MIME_TYPE As String = "text/x-gambas-dragndrop-example"
Private iMouseX As Integer
Private iMouseY As Integer
Public Sub Form_Open()
Dim i As Integer
gdvTemp.Columns.Count = 1
gdvTemp.Rows.Count = 4
For i = 0 To 3
gdvTemp[i, 0].Text = "item " & i
Next
End
Public Sub gdvTemp_MouseDrag()
Dim hImage As Image
Dim sText As String
sText = gdvTemp[gdvTemp.RowAt(Mouse.Y), gdvTemp.ColumnAt(Mouse.X)].Text
hImage = New Image(32 + 8 + gdvTemp.Font.TextWidth(sText), 32, Color.Transparent)
Paint.Begin(hImage)
Paint.Font = gdvTemp.Font
Paint.Text(sText, 34, 0, hImage.Width, 32, Align.Left)
Paint.Fill
Paint.End
Drag.Icon = hImage.Picture
gdvTemp.Drag(sText, MIME_TYPE)
End
Public Sub DrawingArea1_Drop()
DrawingArea1.Refresh
End
Public Sub DrawingArea1_Draw()
Draw.Circle(iMouseX, iMouseY, 10)
End
Public Sub DrawingArea1_MouseMove()
iMouseX = Mouse.X
iMouseY = Mouse.Y
End
- BruceSteers
- Posts: 1574
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Drawingarea drag&drop
hmm , sorry i don't have time to test it but an initial look shows to me you may not want the gdvTemp_MouseDrag() event as this will constantly change. and i'd think possibly become null when you move off the gdvTemp object?
Perhaps try grabbing the info on MouseDown() and set picture on MouseUp() ?
Just a thought.
Perhaps try grabbing the info on MouseDown() and set picture on MouseUp() ?
Just a thought.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Drawingarea drag&drop
Hi Bill,
I am a little confused here. You say 'I wish to drag an item from a gridview to a picturebox' but your example uses a DrawingArea ?
Do you want to drag the text from a GridView Cell to the DrawingArea/PictureBox and put a circle around it?
Can you provide a little more explanation.
I am a little confused here. You say 'I wish to drag an item from a gridview to a picturebox' but your example uses a DrawingArea ?
Do you want to drag the text from a GridView Cell to the DrawingArea/PictureBox and put a circle around it?
Can you provide a little more explanation.
Re: Drawingarea drag&drop
Cogier's doubts are legitimate.
However, regarding the identification of the mouse coordinates (drop point), you have modify, as follows, this routine:
However, regarding the identification of the mouse coordinates (drop point), you have modify, as follows, this routine:
Public Sub DrawingArea1_Drop()
iMouseX = Drag.X
iMouseY = Drag.Y
DrawingArea1.Refresh
End
It is understood that you have to set the "DrawingArea1.Drop" Property to "True".
Last edited by vuott on Friday 20th November 2020 12:01pm, edited 1 time in total.
Europaeus sum !
Amare memorentes atque deflentes ad mortem silenter labimur.
Amare memorentes atque deflentes ad mortem silenter labimur.
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: Drawingarea drag&drop
The full project is a horticultural/gardening database. The drawingarea represents a bed and the gridview a list of plant/shrub names. In fact there's more than one gridview with names. When the item is dropped, the database gets the coordinates for that item so we know what each circle represents.
Perhaps the idea of drawing of a circle confuses the issue so how about dropping an icon in the drawing area instead but it must be at the drop point.
Thanks for all your thoughts on this.
Perhaps the idea of drawing of a circle confuses the issue so how about dropping an icon in the drawing area instead but it must be at the drop point.
Thanks for all your thoughts on this.
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: Drawingarea drag&drop
And thanks for the thought Bruce, that's roughly what I was doing, I just had this foolish notion of making it more 'fancy' with a drag&drop effect!
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Drawingarea drag&drop
I have had a look at this and come up with a place to start. Run this code in a new 'Graphical application'. The next step would be to create a Class (called Plant?) containing text and/or a picture so that you can add this to the DrawingArea. This would give you the option to move the 'Plant' around, delete it etc. Have a look at ScreenShot which uses this principle in the 'Edit' feature. There is a short video that shows this here.
sDragText As String
DrawingAreaGarden As DrawingArea
GridViewData As GridView
Public Sub Form_Open()
Dim iLoop As Integer
Dim sText As String[] = ["Bindweed", "Quackgrass", "Japanese Knotweed", "Canada Thistle", "Nutsedge", "Buckhorn Plantain", "Purslane", "Crabgrass", "Wild Violet", "Ground Ivy"]
With Me
.Width = 500
.Height = 500
.Text = "Bill's garden"
.Arrangement = Arrange.Vertical
.Padding = 5
End With
With GridViewData = New GridView(Me) As "GridViewData"
.Expand = True
.Rows.Count = 0
.Columns.Count = 1
End With
For iLoop = 0 To sText.Max
Inc GridViewData.Rows.Count
GridViewData[iLoop, 0].Text = sText[iLoop]
Next
With DrawingAreaGarden = New DrawingArea(Me) As "DrawingAreaGarden"
.Background = Color.Green
.Expand = True
.Cached = True
.Drop = True
End With
End
Public Sub GridViewData_Click()
sDragText = GridViewData[Last.Row, Last.Column].Text
End
Public Sub GridViewData_MouseDrag()
GridViewData.Drag(sDragText)
End
Public Sub DrawingAreaGarden_Drop()
Paint.Begin(DrawingAreaGarden)
Paint.Text(sDragText, Mouse.ScreenX - DrawingAreaGarden.ScreenX, Mouse.ScreenY - DrawingAreaGarden.ScreenY)
Paint.Fill
Paint.Stroke
Paint.End
End