Move a Fom/Control ONLY using the MouseMove Event, Nothing Else!
Ive, done it, hehhee
AI
Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Codice sorgente
'Example code.
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
MouseDragging(e, Me)
End Sub
Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
MouseDragging(e, Me.Button1)
End Sub
'Copyright Andrew Vos 2004 :)
Private Sub MouseDragging(ByVal e As MouseEventArgs, ByVal Control As Control)
Static OldPosition As New Point(-1, -1)
If Not (e.Button = Nothing) Then
If e.Button = MouseButtons.Left Then
If (OldPosition.X = -1) And (OldPosition.Y = -1) Then OldPosition = New Point(e.X, e.Y)
If e.Y <> OldPosition.Y Then
Control.Top += e.Y - OldPosition.Y 'move Up/Down
End If
If e.X <> OldPosition.X Then
Control.Left += e.X - OldPosition.X 'move Left/Right
End If
End If
Else
'button is nothing, maybe it was lifted.
OldPosition = New Point(-1, -1)
End If
End Sub
Commenti originali (3)
Recuperato da Wayback Machine