1个回答
展开全部
Rem 放一个Label控件来移动窗体 Rem 移动没有标题栏窗体的声明 Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Private Type POINTAPI X As Long Y As Long End Type Dim scrPT As POINTAPI Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) On Error Resume Next Me.SetFocus If Button = 1 Then '判断是不是点击了左键 GetCursorPos scrPT '记录鼠标坐标 End If End Sub '在每一次MouseMove事件中进行坐标处理 Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Me.WindowState <> 2 Then If Button = 1 Then Dim pt As POINTAPI '定义一个用于记录鼠标新位置的POINTAPI变量 GetCursorPos pt '获得新坐标 Me.Left = Me.Left + (pt.X - scrPT.X) * 15 '计算鼠标位移,相应的调整窗体位置 Me.Top = Me.Top + (pt.Y - scrPT.Y) * 15 '把新坐标变量值赋给旧坐标变量 scrPT = pt '下一次事件触发,如此循环就可以事件窗体的平滑移动。 End If End If End Sub
记得采纳啊
记得采纳啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询