如何做到拖动窗体窗体就跟着鼠标移动
3个回答
展开全部
简单,不要用api吧
Dim x0 As Long, y0 As Long '记录按下鼠标的位置
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
x0 = X '记录位置
y0 = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '按下鼠标左键
Me.Left = Me.Left + X - x0
Me.Top = Me.Top + Y - y0
End If
End Sub
Dim x0 As Long, y0 As Long '记录按下鼠标的位置
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
x0 = X '记录位置
y0 = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then '按下鼠标左键
Me.Left = Me.Left + X - x0
Me.Top = Me.Top + Y - y0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'把以下代码加入就可以了
Const HTCAPTION = 2
Const WM_NCLBUTTONDOWN = &HA1
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = 1 Then
Dim ReturnVal As Long
x = ReleaseCapture()
ReturnVal = SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub
Const HTCAPTION = 2
Const WM_NCLBUTTONDOWN = &HA1
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = 1 Then
Dim ReturnVal As Long
x = ReleaseCapture()
ReturnVal = SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你也可以不用API来实现
Dim PrevX As Long, PrevY As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
PrevX = X: PrevY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Me.Move Me.Left + X - PrevX, Me.Top + Y - PrevY
End Sub
Dim PrevX As Long, PrevY As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
PrevX = X: PrevY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Me.Move Me.Left + X - PrevX, Me.Top + Y - PrevY
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询