Need Help with Visual Basic Drag and Drop
-
I'm setting up a card game; solitaire, and I want to drag one card on top of a bitmap that looks like a blank card. I want the card image to stay on top IF it matches a certain variable (array of an image). I have the source images as Image1(52) array of cards, and the target images as Hearts(12). I will do Clubs, etc., but am just starting with hearts suit to test. Here is my code so far. I'm having difficulty on trying to figure out how to drag the image and copy it on top of another image if it equals that image's properties (array #). Private Sub Image1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) Index = 12 If TypeOf Source Is Image Then Image1(Index).Picture = Source.Picture End If End Sub Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Index = 12 If Button = vbLeftButton Then Image1(Index).Drag vbBeginDrag End If End Sub Private Sub Image1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Index = 12 If Button = vbLeftButton Then Image1(Index).Drag vbEndDrag End If End Sub Any ideas would be appreciated.
-
I'm setting up a card game; solitaire, and I want to drag one card on top of a bitmap that looks like a blank card. I want the card image to stay on top IF it matches a certain variable (array of an image). I have the source images as Image1(52) array of cards, and the target images as Hearts(12). I will do Clubs, etc., but am just starting with hearts suit to test. Here is my code so far. I'm having difficulty on trying to figure out how to drag the image and copy it on top of another image if it equals that image's properties (array #). Private Sub Image1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) Index = 12 If TypeOf Source Is Image Then Image1(Index).Picture = Source.Picture End If End Sub Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Index = 12 If Button = vbLeftButton Then Image1(Index).Drag vbBeginDrag End If End Sub Private Sub Image1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Index = 12 If Button = vbLeftButton Then Image1(Index).Drag vbEndDrag End If End Sub Any ideas would be appreciated.
A two-step implementation for drag'n'drop; - Start the dragdrop operation by calling the
DoDragDrop
method in theMouseDown
event. - SetAllowDrop
toTrue
for the control that you're going to drop things on. MSDN has dedicated a page to the topic Drag&Drop in VB.NET[^] :)I are troll :)
-
A two-step implementation for drag'n'drop; - Start the dragdrop operation by calling the
DoDragDrop
method in theMouseDown
event. - SetAllowDrop
toTrue
for the control that you're going to drop things on. MSDN has dedicated a page to the topic Drag&Drop in VB.NET[^] :)I are troll :)
-
Thanks, but I'm doing this in VB6, not .NET. So, it is another name for the method. It won't take the parameters you gave me.
-
ymilan wrote:
Thanks, but I'm doing this in VB6, not .NET.
No problem, there are also VB6 tutorials[^] available :)
I are troll :)
Thanks, I read this and tried with basically I have an array of cards in design view; trying to drag one of those cards to another array of cards. Image1(12) to Hearts(12) as an example. Trying to drag over an icon already in the Hearts(12) position and drop on that icon "after" it equals the value of the card. Kind of weird how I'm doing it, but I wanted to have a visual blank picture of a card in white, and the let's say, hearts King card either underneath hidden or be the same value as the white card. Then when the hearts King is found on the left, it gets dragged and dropped if it matches the king card on the right. I hope I make sense. Having problems with the array. Compiler won't accept Hearts(12) or Image1(12); says it needs an identifier, so I tried this an it doesn't work. Any ideas would be much appreciated. Thanks in advance. Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) Index = 52 Image1 = Image1(Index) If Button = vbLeftButton Then Image1.Drag vbBeginDrag = 1 End If End Sub Private Sub Image1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) Index = 52 Image1 = Image1(Index) If Button = vbLeftButton Then Imag1.Drag vbEndDrag = 0 End If End Sub Private Sub Hearts_DragOver(Index As Integer, source As Control, x As Single, y As Single, State As Integer) Index = 12 Hearts = Hearts(Index) Hearts(Index).Picture = source.Picture State = 0 End Sub Private Sub Hearts_DragDrop(Index As Integer, source As Control, x As Single, y As Single) Index = 12 Hearts = Hearts(Index) Hearts(Index).Picture = source.Picture End Sub
-
Thanks, I read this and tried with basically I have an array of cards in design view; trying to drag one of those cards to another array of cards. Image1(12) to Hearts(12) as an example. Trying to drag over an icon already in the Hearts(12) position and drop on that icon "after" it equals the value of the card. Kind of weird how I'm doing it, but I wanted to have a visual blank picture of a card in white, and the let's say, hearts King card either underneath hidden or be the same value as the white card. Then when the hearts King is found on the left, it gets dragged and dropped if it matches the king card on the right. I hope I make sense. Having problems with the array. Compiler won't accept Hearts(12) or Image1(12); says it needs an identifier, so I tried this an it doesn't work. Any ideas would be much appreciated. Thanks in advance. Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) Index = 52 Image1 = Image1(Index) If Button = vbLeftButton Then Image1.Drag vbBeginDrag = 1 End If End Sub Private Sub Image1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) Index = 52 Image1 = Image1(Index) If Button = vbLeftButton Then Imag1.Drag vbEndDrag = 0 End If End Sub Private Sub Hearts_DragOver(Index As Integer, source As Control, x As Single, y As Single, State As Integer) Index = 12 Hearts = Hearts(Index) Hearts(Index).Picture = source.Picture State = 0 End Sub Private Sub Hearts_DragDrop(Index As Integer, source As Control, x As Single, y As Single) Index = 12 Hearts = Hearts(Index) Hearts(Index).Picture = source.Picture End Sub
-
That error is thrown in the
_DragDrop
, on the line below?Hearts = Hearts(Index)
What type is the left "Hearts"? Is it a PictureBox?
I are troll :)
Starts with Image1(index). I don't think I can make Image1 = Image1(index); an array. Maybe I can just use the Set command? Let me explain more; On the left, in design view, I have 52 images of cards in suits. I shuffle them when the start button is pressed. Now, I want to move any of the bottom cards on the left to positions on the right. On the right, there is, let's say, 13 cards of Hearts suit. There is an image on them, not a picture box. Just an image of blank cards. I want that so the player will see where to drop a card. If the card doesn't match the card on the right, then it cannot be dropped there, and basically flies back to it's position on the left, where the player can only put that card in, let's say, a holding area and drop it there for use later. It is solitaire, but played a different way. Hope this helps.... Thanks in advance.
-
That error is thrown in the
_DragDrop
, on the line below?Hearts = Hearts(Index)
What type is the left "Hearts"? Is it a PictureBox?
I are troll :)
Silly me; I figured it out. This works.... Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) Index = 12 If TypeOf Source Is Image Then Hearts(Index).Picture = Source.Picture End If End Sub Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Index = 12 If Button = vbLeftButton Then Image1(Index).Drag vbBeginDrag End If End Sub Private Sub Image1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Index = 12 If Button = vbLeftButton Then Image1(Index).Drag vbEndDrag End If End Sub
-
Silly me; I figured it out. This works.... Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) Index = 12 If TypeOf Source Is Image Then Hearts(Index).Picture = Source.Picture End If End Sub Private Sub Image1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Index = 12 If Button = vbLeftButton Then Image1(Index).Drag vbBeginDrag End If End Sub Private Sub Image1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) Index = 12 If Button = vbLeftButton Then Image1(Index).Drag vbEndDrag End If End Sub