VB中如何让none风格的窗体随鼠标点击移动而移动

 我来答
crazy0qwer
2013-04-30 · TA获得超过3299个赞
知道大有可为答主
回答量:4020
采纳率:71%
帮助的人:1311万
展开全部

窗体,一个timer1 .

Option Explicit
Option 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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
神龙令主
2013-05-03 · TA获得超过803个赞
知道小有建树答主
回答量:580
采纳率:0%
帮助的人:209万
展开全部
无需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
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式