Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Need Help with Visual Basic Drag and Drop

Need Help with Visual Basic Drag and Drop

Scheduled Pinned Locked Moved Visual Basic
databasegraphicsgame-devdata-structures
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    ymilan
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • Y ymilan

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      A two-step implementation for drag'n'drop; - Start the dragdrop operation by calling the DoDragDrop method in the MouseDown event. - Set AllowDrop to True 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 :)

      Y 1 Reply Last reply
      0
      • L Lost User

        A two-step implementation for drag'n'drop; - Start the dragdrop operation by calling the DoDragDrop method in the MouseDown event. - Set AllowDrop to True 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 :)

        Y Offline
        Y Offline
        ymilan
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • Y ymilan

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          ymilan wrote:

          Thanks, but I'm doing this in VB6, not .NET.

          No problem, there are also VB6 tutorials[^] available :)

          I are troll :)

          Y 1 Reply Last reply
          0
          • L Lost User

            ymilan wrote:

            Thanks, but I'm doing this in VB6, not .NET.

            No problem, there are also VB6 tutorials[^] available :)

            I are troll :)

            Y Offline
            Y Offline
            ymilan
            wrote on last edited by
            #5

            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

            L 1 Reply Last reply
            0
            • Y ymilan

              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

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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 :)

              Y 2 Replies Last reply
              0
              • L Lost User

                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 :)

                Y Offline
                Y Offline
                ymilan
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • L Lost User

                  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 :)

                  Y Offline
                  Y Offline
                  ymilan
                  wrote on last edited by
                  #8

                  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

                  L 1 Reply Last reply
                  0
                  • Y ymilan

                    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

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Nice :)

                    I are troll :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups