Hi,
I am using the below code which simply allows a single button control
to be dragged and dropped anywhere around a form. My problem is that
want to move about 100 buttons on the form. Is there anyway to modify
the code so that any buttons added on the form will be able to be
dragged and dropped?
Many Thanks!
Marc
Private Sub btnMove_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles btnMove.MouseDo wn
If e.Button = Windows.Forms.M ouseButtons.Lef t Then
Dragging = True
mousex = -e.X
mousey = -e.Y
Dim clipleft As Integer = Me.PointToClien t(MousePosition ).X
- btnMove.Locatio n.X
Dim cliptop As Integer = Me.PointToClien t(MousePosition ).Y
- btnMove.Locatio n.Y
Dim clipwidth As Integer = Me.ClientSize.W idth -
(btnMove.Width - clipleft)
Dim clipheight As Integer = Me.ClientSize.H eight -
(btnMove.Height - cliptop)
Windows.Forms.C ursor.Clip = Me.RectangleToS creen(New
Rectangle(clipl eft, cliptop, clipwidth, clipheight))
btnMove.Invalid ate()
End If
End Sub
Private Sub btnMove_MouseMo ve(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles btnMove.MouseMo ve
If Dragging Then
'move control to new position
Dim MPosition As New Point()
MPosition = Me.PointToClien t(MousePosition )
MPosition.Offse t(mousex, mousey)
'ensure control cannot leave container
btnMove.Locatio n = MPosition
End If
End Sub
Private Sub btnMove_MouseUp (ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles btnMove.MouseUp
If Dragging Then
'end the dragging
Dragging = False
'Me.Capture = False
Windows.Forms.C ursor.Clip = Nothing
btnMove.Invalid ate()
End If
End Sub
I am using the below code which simply allows a single button control
to be dragged and dropped anywhere around a form. My problem is that
want to move about 100 buttons on the form. Is there anyway to modify
the code so that any buttons added on the form will be able to be
dragged and dropped?
Many Thanks!
Marc
Private Sub btnMove_MouseDo wn(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles btnMove.MouseDo wn
If e.Button = Windows.Forms.M ouseButtons.Lef t Then
Dragging = True
mousex = -e.X
mousey = -e.Y
Dim clipleft As Integer = Me.PointToClien t(MousePosition ).X
- btnMove.Locatio n.X
Dim cliptop As Integer = Me.PointToClien t(MousePosition ).Y
- btnMove.Locatio n.Y
Dim clipwidth As Integer = Me.ClientSize.W idth -
(btnMove.Width - clipleft)
Dim clipheight As Integer = Me.ClientSize.H eight -
(btnMove.Height - cliptop)
Windows.Forms.C ursor.Clip = Me.RectangleToS creen(New
Rectangle(clipl eft, cliptop, clipwidth, clipheight))
btnMove.Invalid ate()
End If
End Sub
Private Sub btnMove_MouseMo ve(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles btnMove.MouseMo ve
If Dragging Then
'move control to new position
Dim MPosition As New Point()
MPosition = Me.PointToClien t(MousePosition )
MPosition.Offse t(mousex, mousey)
'ensure control cannot leave container
btnMove.Locatio n = MPosition
End If
End Sub
Private Sub btnMove_MouseUp (ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles btnMove.MouseUp
If Dragging Then
'end the dragging
Dragging = False
'Me.Capture = False
Windows.Forms.C ursor.Clip = Nothing
btnMove.Invalid ate()
End If
End Sub
Comment