VBA窗体移动问题

求高手帮忙!可以解决的留下QQ,我传原件给你!谢谢
2025-04-27 18:37:45
推荐回答(1个)
回答1:

先定义全局变量
iX, iY

Private Sub imgMoveBar_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
iX = X
iY = Y
End Sub

Private Sub imgMoveBar_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button <> xlPrimaryButton Then Exit Sub
Application.EnableEvents = False
Me.Top = Me.Top + Y - iY
Me.Left = Me.Left + X - iX
Application.EnableEvents = True
End Sub