M
Marc
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_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Dragging = True
mousex = -e.X
mousey = -e.Y
Dim clipleft As Integer = Me.PointToClient(MousePosition).X
- btnMove.Location.X
Dim cliptop As Integer = Me.PointToClient(MousePosition).Y
- btnMove.Location.Y
Dim clipwidth As Integer = Me.ClientSize.Width -
(btnMove.Width - clipleft)
Dim clipheight As Integer = Me.ClientSize.Height -
(btnMove.Height - cliptop)
Windows.Forms.Cursor.Clip = Me.RectangleToScreen(New
Rectangle(clipleft, cliptop, clipwidth, clipheight))
btnMove.Invalidate()
End If
End Sub
Private Sub btnMove_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseMove
If Dragging Then
'move control to new position
Dim MPosition As New Point()
MPosition = Me.PointToClient(MousePosition)
MPosition.Offset(mousex, mousey)
'ensure control cannot leave container
btnMove.Location = MPosition
End If
End Sub
Private Sub btnMove_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseUp
If Dragging Then
'end the dragging
Dragging = False
'Me.Capture = False
Windows.Forms.Cursor.Clip = Nothing
btnMove.Invalidate()
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_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Dragging = True
mousex = -e.X
mousey = -e.Y
Dim clipleft As Integer = Me.PointToClient(MousePosition).X
- btnMove.Location.X
Dim cliptop As Integer = Me.PointToClient(MousePosition).Y
- btnMove.Location.Y
Dim clipwidth As Integer = Me.ClientSize.Width -
(btnMove.Width - clipleft)
Dim clipheight As Integer = Me.ClientSize.Height -
(btnMove.Height - cliptop)
Windows.Forms.Cursor.Clip = Me.RectangleToScreen(New
Rectangle(clipleft, cliptop, clipwidth, clipheight))
btnMove.Invalidate()
End If
End Sub
Private Sub btnMove_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseMove
If Dragging Then
'move control to new position
Dim MPosition As New Point()
MPosition = Me.PointToClient(MousePosition)
MPosition.Offset(mousex, mousey)
'ensure control cannot leave container
btnMove.Location = MPosition
End If
End Sub
Private Sub btnMove_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles btnMove.MouseUp
If Dragging Then
'end the dragging
Dragging = False
'Me.Capture = False
Windows.Forms.Cursor.Clip = Nothing
btnMove.Invalidate()
End If
End Sub