我不知道你想要的是什么效果,所以准备了两个版本:
***版本一***左键单击后可以移动,再次单击停止移动:
Dim bMove As Boolean '判断可不可以移动
Dim oldX!, oldY! '!是Single的缩写
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bMove Then
Command1.Left = Command1.Left - oldX + X
Command1.Top = Command1.Top - oldY + Y
End If
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '1就是鼠标左键
bMove = Not bMove
oldX = X
oldY = Y
End If
End Sub
***版本二***左键按下时可以拖动:
Dim oldX!, oldY! '!是Single的缩写
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '1就是鼠标左键
oldX = X
oldY = Y
End If
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Command1.Left = Command1.Left - oldX + X
Command1.Top = Command1.Top - oldY + Y
End If
End Sub
不对的,用图片控件做棋子要好得多!
自己可以定义坐标,判断你点击的坐标,用MOVE方法移动棋子。
以上没有一个是确切的
要command1与form配合起来用,包你鼠标到哪里,command1到那里.我有现成的程序代码.不过只提供给朋友.
Dim Xx, Yy
Private Sub command1_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single)
If Button = 1 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 = 1 Then
Command1.Left = X - Xx + Command1.Left
Command1.Top = y - Yy + Command1.Top
End If
End Sub
好吧,我也加一种
Dim Xx, Yy
Private Sub command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Command1.Left = X - Xx + Command1.Left
Command1.Top = y - Yy + Command1.Top
Else
Xx=x
Yy=y
End If
End Sub
Private Sub Command1_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move (X - Source.Width / 2), (Y - Source.Height / 2)
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Drag 1
End Sub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Drag 2
End Sub