Windows Develop Bookmark and Share   
 index > Windows Forms General > How can I drag controls around on a form? PLEASE HELP!!!
 

How can I drag controls around on a form? PLEASE HELP!!!

I'm trying to make a game. I have some pictures and labels on my form and what I want to be able to do is drag each label and place it in a text box next to its corresponding pictures. This is the code I have so far. What happens is that when press the left mouse button, it grabs the label and I can drag it anywhere. However, the picture is not dropped when I release the mouse button. I have to click again to drop the picture. Any ideas? How can I fix this?

Public

Class frmcattypes

Dim xd As Boolean

Public Sub frmcattypes_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

If xd = True Then

Button1.Location =

New Point(e.X, e.Y)

End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

xd =

True

End Sub

Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown

xd =

True

End Sub

Thanks in advance!

  • Edited byrklm Friday, June 26, 2009 11:47 AM
  • Moved byCindy MeisterMVPSaturday, June 27, 2009 8:09 AMnot VSTO-related (From:Visual Studio Tools for Office)
  • Changed TypeLinda LiuMSFT, ModeratorFriday, July 03, 2009 9:32 AMNo follow up from OP
  •  
rklm  Friday, June 26, 2009 11:30 AM
Hi Rklm,

>However, the picture is not dropped when I release the mouse button.

Could you tell me what you mean in the above sentence?

From the sample code you showed, it seems that you justmove a Buttonaroundwithinthe form using the Mouse at run time.

Sincerely,
Linda Liu


Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Thursday, July 02, 2009 10:06 AM
We are changing the issue type to “General Discussion�because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question�by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Linda Liu  Friday, July 03, 2009 9:33 AM

You can use google to search for other answers

Custom Search

More Threads

• Will there be a Data Repeater control released in C# for Windows Forms?
• Treeview in UserControl not updating
• datagridviewcombox error.
• Where are stored images added directly to imageList?
• How to pass multi dimensional string array to VB.
• Form question
• CoInitializeSecurity fails with VS 2005
• Visual Studio .Net Professional upgrade
• XP Home/HP Professional
• Custom Windows service is not working properly