'以下代码可以托动窗体中Label1控件
Dim a As Boolean '定义一个布尔变量(只要是布尔变量,只可能有两个值:True 或者 false)
Dim b As Integer
Dim c As Integer
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If a = True Then
Label1.Left = Label1.Left + X - b
Label1.Top = Label1.Top + Y - c
End If
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '当按下鼠标时,控件可以拖动
b = X '鼠标按下时Label1与鼠标的横坐标
c = Y '鼠标按下时Label1与鼠标的坚坐标
a = True
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) '松开鼠标时,控件不可拖动
a = False
End Sub