VB代码问题,类似于QQ的窗体有吸附功能,把窗体移动到屏幕边缘能悬挂起来的…

 我来答
一方乐土养生f
2012-03-03 · TA获得超过1044个赞
知道小有建树答主
回答量:691
采纳率:0%
帮助的人:523万
展开全部
用timer判断form的位置,如果top=0就把top-form1.height'留一点点边缘出来也可以。。。
然后再用getcursorpos获取鼠标位置,如果在窗体下边缘就控制top=0

Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Sub Timer1_Timer()
Dim p As POINTAPI, r As RECT
GetCursorPos p
GetWindowRect Me.hwnd, r

If r.Top <= 0 And (Not (p.y < r.Bottom And p.x > r.Left And p.x < r.Right)) Then
Form1.Top = -Form1.Height + 100
End If

If p.x > r.Left And p.x < r.Right And p.y < r.Bottom Then
If r.Top <= 0 Then
SetWindowPos Me.hwnd, -2, r.Left, 0, 0, 0, 1
Else
SetWindowPos Me.hwnd, -2, r.Left, r.Top, 0, 0, 1
End If
End If
End Sub

只做了顶端吸附,侧边和低端也是差不多的
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式