Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

   I'm trying to write a base environment that is similar to all those Microsoft card games like 'Solitare' and 'Freecell'. The part right now where im running into trouble is the drag-n-drop part.

   Right now I am simply grabing a location on mouse_up and setting the Card Image to that location (or something like that)

   But what I want to do is to have the card follow the cursor until the left-mouse is let up. But VB does not handle an event until the current function is finished.

   Is there any way to check if the left-mouse has been let up before the mouse-down function is complete OR am I just doing this the hard way?

  • *Experts*
Posted
I dont know if im understanding your problem well :), are you saying that you are trying to move an image with your mouse? Are you using a picture box? If you are trying to get your image moving with the mouse then use the MouseMove event to get the coordinates of the mouse each time it moves.
Posted

What I want to do is have a picturebox of a card. If I want to drag it across the screen I click it, drag the image with the mouse button down, and let go. As I am dragging the mouse I want the picturebox to follow as well.

 

The problem I am having is that if i want the process to begin with a mouse down and i write a routine that has the picturebox follow the mouse while the button is still down, how do I get the form/system to recognize that the mouse-up has occured if events are queued and only handled once the last one has been handled?

  • *Experts*
Posted

Try this example:

(cardpic here is the name of the picturebox, but you can make it any picurebox using the sender method of the mouse events and adding one more variable)

'tells you if the object should be dragged
Dim dragging As Boolean = False
'values used to make the moving smooth
Dim x, y As Integer

Private Sub cardpic_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cardpic.MouseDown
 'set to dragging
 dragging = True
 x = cardpic.PointToClient(Me.Cursor.Position).X
 y = cardpic.PointToClient(Me.Cursor.Position).Y
End Sub

Private Sub cardpic_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cardpic.MouseUp
   'dont drag anymore
   dragging = False
End Sub

Private Sub cardpic_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cardpic.MouseMove
 'if the object should be dragged change the location
 If dragging Then
    cardpic.Location = New Point(Me.PointToClient(Me.Cursor.Position).X - x, Me.PointToClient(Me.Cursor.Position).Y - y)
 End If
End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...