VB中如何让none风格的窗体随鼠标点击移动而移动
2个回答
展开全部
窗体,一个timer1 .
Option ExplicitOption Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim p As POINTAPI, X1 As Long, Y1 As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Interval = 50
Timer1.Enabled = True
GetCursorPos p
X1 = p.X
Y1 = p.Y
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
GetCursorPos p
Form1.Left = Form1.Left + (p.X - X1) * 15
Form1.Top = Form1.Top + (p.Y - Y1) * 15
X1 = p.X
Y1 = p.Y
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
无需API、无需其他控件!
Option Explicit
Dim mouseIsDown As Boolean
Dim cx As Single
Dim cy As Single
Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mouseIsDown = True
cx = X
cy = Y
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If mouseIsDown Then
Move Left + (X - cx), Top + (Y - cy)
End If
End Sub
Private Sub form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
mouseIsDown = False
End Sub
Option Explicit
Dim mouseIsDown As Boolean
Dim cx As Single
Dim cy As Single
Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
mouseIsDown = True
cx = X
cy = Y
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If mouseIsDown Then
Move Left + (X - cx), Top + (Y - cy)
End If
End Sub
Private Sub form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
mouseIsDown = False
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询