Dragging a control

  • Thread starter Thread starter Tull Clancey
  • Start date Start date
T

Tull Clancey

Does anyone have, or can anyone suggest a URL for code to drag a control
around a form at run time? VB.Net 2003.

I have written stuff in VB6 to do this before, but a long time ago and I
don't have the code to refer to anymore.

Cheers,
Tull.
 
This is sample code for dragging a button at runtime, should be easy to
modify for other controls

Hope this helps
<<<<<<code>>>>>>


Private dragging As Boolean
Private beginX, beginY As Integer


Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown


dragging = True
beginX = e.X
beginY = e.Y


End Sub


Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
If dragging = True Then
Button2.Location = New Point(Button2.Location.X + e.X -
beginX,Button2.Location.Y + e.Y - beginY)
Me.Refresh()
End If
End Sub


Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp


dragging = False


End Sub
 
Back
Top