在窗口放一个按钮,在复制下面代码运行测试ok!!!
Dim xx, yy, ax, ay As Long
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
xx = X
yy = Y
End If
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
ax = Command1.Left + X
ay = Command1.Top + Y
Command1.Top = ay - yy
Command1.Left = ax - xx
End If
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Print "你点击了按钮了"
If Button = 2 Then Print "你移动按钮了"
End Sub
Private Sub Form_Load()
Command1.Caption = "鼠标左键点击,鼠标右键移动"
End Sub