Pros:
- Simple, easy to Program
- Easy to understand for the beginner
Cons
- May flicker as controls are drawn and redrawn
- Windows seems not to like this method much :)
Insert this code snippet in your form that you want to be movable :
#Region "Declarations"
Dim m As Integer = 0
Dim n As Integer = 0
Dim isMouseDown As Boolean = False
Dim isMouseDownAgain As Boolean = False
#End Region
#Region "Form Events"
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If isMouseDownAgain = True Then
isMouseDown = False
isMouseDownAgain = False
End If
m = MousePosition.X - Me.Location.X
n = MousePosition.Y - Me.Location.Y
Me.Location = New Point(MousePosition.X - m, MousePosition.Y - n)
If isMouseDown = True Then
isMouseDownAgain = True
Else
isMouseDownAgain = False
End If
isMouseDown = True
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If isMouseDown = True And isMouseDownAgain <> True Then
Me.Location = New Point(MousePosition.X - m, MousePosition.Y - n)
Else
Exit Sub
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
isMouseDown = False
Me.Location = New Point(MousePosition.X - m, MousePosition.Y - n)
End Sub
#End Region
Comments
Post a Comment
No spam please :)