vb 关于控件拖动的问题
下面的代码可以完成Picture1的拖动Dimx1AsLong,x2AsLong,y1AsLong,y2AsLong,MousedownAsBooleanPrivateS...
下面的代码可以完成Picture1的拖动
Dim x1 As Long, x2 As Long, y1 As Long, y2 As Long, Mousedown As Boolean
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
x1 = X
y1 = Y
Mousedown = True
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
x2 = X
y2 = Y
If Mousedown = True Then Picture1.Move Picture1.Left - x1 + x2, Picture1.Top - y1 + y2
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Mousedown = False
End Sub
现在我的问题是,我的窗体上有若干个控件,我希望在使用的时候都能够拖动,我又不希望重复的写代码,能不能够把它做成一个函数,对任何可以拖动的控件进行调用这个函数而生效呢?
求高手帮忙。 展开
Dim x1 As Long, x2 As Long, y1 As Long, y2 As Long, Mousedown As Boolean
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
x1 = X
y1 = Y
Mousedown = True
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
x2 = X
y2 = Y
If Mousedown = True Then Picture1.Move Picture1.Left - x1 + x2, Picture1.Top - y1 + y2
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Mousedown = False
End Sub
现在我的问题是,我的窗体上有若干个控件,我希望在使用的时候都能够拖动,我又不希望重复的写代码,能不能够把它做成一个函数,对任何可以拖动的控件进行调用这个函数而生效呢?
求高手帮忙。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询