PDA

Click to See Complete Forum and Search --> : Drag and Drop - I thought games / graphics programmers might know...


gulliver
Feb 4th, 2001, 02:54 PM
***This message was originally posted in the general Q&A section but I was having no luck - hopefully I'll get more help here...***

Can someone please help me? I have a form with two picture boxes, picDragDrop1 and picDragDrop2. I have an image in both (the same image) but in picDragDrop1 it is visible and in picDragDrop2 it is not visible.

I am trying to code the dragdrop and dragover procedures so that:

1) when the picture is dragged out of the first picture box and is dropped on the form, it appears to "snap" back into the first picture box

2) when the picture is dragged out of the first picture box and is dropped onto the second picture box, it appears in the second picture box but vanishes from the first (i.e. as if it "moved")

3) when the picture is dragged within the first picture box or is dragged around anywhere on the form but then dropped back onto the first picture box, it reappears in the first picture box as it originally was.

I am having trouble only with this last part (part 3). When I drop it back onto the first picture box it vanishes completely. Why is this? Here is the code I have so far:

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
picDragDrop1.Visible = True
End Sub

Private Sub picDragDrop1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
picDragDrop1.Visible = False
End Sub

Private Sub picDragDrop2_DragDrop(Source As Control, X As Single, Y As Single)
picDragDrop2.Picture = Source.Picture
End Sub

Sastraxi
Feb 5th, 2001, 07:16 PM
Try this:


Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
picDragDrop1.Visible = True
End Sub

Private Sub picDragDrop1_DragDrop(Source As Control, X As Single, Y As Single)
If source=picDragDrop2 then
picDragDrop2.visible = False
picDragDrop1.visible = True
end if

End Sub

Private Sub picDragDrop2_DragDrop(Source As Control, X As Single, Y As Single)
If source=picDragDrop1 then
picDragDrop2.visible = True
picDragDrop1.visible = False
end if
End Sub


The reason that it didnt work (i think) is because you had dragOVER instead of dragDROP

Sastraxi
Feb 6th, 2001, 06:18 PM
Sorry, that probably wont work. I didn't understand the question at first. You'll need to tweak it.

gulliver
Feb 20th, 2001, 12:20 PM
Hi sastraxi,

I'm sorry, but your suggestion did not work the way I wanted it.

Shame on all of you who could not help me properly with this! That includes you programmers in the General VB Questions section too!

You will all, no doubt, appreciate the fact that I have successfully managed to figure out the answer to my problem on my own! Here's how I did it (I had to use the DragDrop event procedures of the two frame controls containg the pictures):

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
If X < Me.Width / 2 Then
picDragDrop1.Visible = True
Else
picDragDrop2.Visible = True
End If
End Sub

Private Sub fraPic1_DragDrop(Source As Control, X As Single, Y As Single)
picDragDrop1.Visible = True
End Sub

Private Sub fraPic2_DragDrop(Source As Control, X As Single, Y As Single)
picDragDrop2.Visible = True
End Sub

Private Sub picDragDrop1_DragDrop(Source As Control, X As Single, Y As Single)
picDragDrop2.Visible = True
End Sub

Private Sub picDragDrop1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
picDragDrop1.Visible = False
End Sub

Private Sub picDragDrop2_DragDrop(Source As Control, X As Single, Y As Single)
picDragDrop2.Visible = True
End Sub

Private Sub picDragDrop2_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
picDragDrop2.Visible = False
End Sub



Hope this might help someone else who was having the same problem!

Sastraxi
Feb 20th, 2001, 03:57 PM
Shame on me too? Gosh, gulliver, I'm hurt! :)

-just kidding

Sastraxi
Feb 20th, 2001, 03:58 PM
Oh yeah, and gulliver, this is for you:
:P
:) - sorry I couldn't help you, but I'm not that good on the subject either. Cheers!

gulliver
Feb 20th, 2001, 04:36 PM
Thanks for trying sastrxi. No hard feelings OK?
:-)