這程式示範兩個button的滑鼠拖曳
只要將buttonclass,buttonplat改成你的button 名稱就可用
Private Sub Buttonclass_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonclass.MouseDown
Timer1.Enabled = True
Timer1.Start()
objectposition = Buttonclass.Location
cursorpoint = Cursor.Position
End Sub
Private Sub Buttonclass_Mouseup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonclass.MouseUp
Timer1.Stop()
objectposition = Buttonclass.Location
cursorpoint = Cursor.Position
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Buttonclass.Location = objectposition - cursorpoint + Cursor.Position
End Sub
Private Sub buttonplat_mousedown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonplat.MouseDown
Timer2.Enabled = True
Timer2.Start()
objectposition = Buttonplat.Location
cursorpoint = Cursor.Position
End Sub
Private Sub buttonplat_mouseup(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Buttonplat.MouseUp
Timer2.Stop()
objectposition = Buttonplat.Location
cursorpoint = Cursor.Position
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Buttonplat.Location = objectposition - cursorpoint + Cursor.Position
End Sub
End Class
沒有留言:
張貼留言