10-27-2006, 11:53 AM
I'd like to be able to move controls around at runtime. I tried this:
Private Sub txtTime_Mousemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtTime.MouseMove
txtTime.Location = New Point(e.X, e.Y)
but it doesn't work smoothly. What is the best way?
10-27-2006, 12:36 PM
Generally you need to use the MouseDown, MouseMove and MouseUp events together.
In MouseDown, set a varialbe that says you're dragging.
In MouseMove check the variable to see if you're dragging.
If Dragging, then calculate the new position of teh control.
In Mouse Up clear the variable.
10-27-2006, 12:39 PM
Also in that event, e.X and e.Y are coordinates of your textbox, not the form.
I bet it bet it jerks around frantically, right?
10-27-2006, 12:50 PM
How do I get the cursors location with respect to the form?
10-27-2006, 12:58 PM
I do mostly WebApps, but it sounds like Form.MousePosition (http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.mouseposition.aspx) is what you're looking for.
10-29-2006, 02:23 PM
Hi, check this link, I did a sample project that I think will help:
10-30-2006, 11:07 AM
Here is another thread that might be helpful:
You can see in post #10 that I posted some code which allows the user to use a marquee to select a number of controls and drag/drop and well as cut and paste the controls.
I can post the actual project to this thread if you like.