请教关于mouse_down,mouse_up,和mouse_move 的应用

sekfore 2001-07-27 12:46:25
我在做一个程序,想用鼠标可以拖动form。可是由于mouse_move是不断产生的。导致form不断的“颤抖”。请大家帮忙解决啊,谢谢了! :)
...全文
116 点赞 收藏 11
写回复
11 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sekfore 2001-07-29
我知道了。是层叠事件
回复
xxlroad 2001-07-28
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 Any) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const HTCAPTION = 2
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0
End Sub
回复
tg123 2001-07-28
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Private Sub Form1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture

SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0

End Sub
回复
DevilXelloss 2001-07-27
在 Form_MouseDown() 里面:
ReleaseCapture
SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
回复
DevilXelloss 2001-07-27
你要拖动 Form,只需在 Form_MouseDown() 用 SendMessage 向 Form 发送 WM_NCLBUTTONDOWN 消息就可以了,把 HitTest 设置为 Caption,就会模拟出拖动窗体标题栏的效果。
回复
songyangk 2001-07-27
据我所知,在VB里用这种方法调用,就是抖呀!
回复
herony 2001-07-27
应该只识别MouseMove吧,如果 Down也识别,是不颤抖了,可是却跳了,我感觉还是在move时可以调用一个延时的程序,比如50ms,这样就不会颤抖了,具体使用Sleep API函数
回复
Amoon 2001-07-27
hehe,很老的办法嘛。
回复
sekfore 2001-07-27
谢谢!
回复
sssoft 2001-07-27
Dim ox&, oy&, sx&, sy&

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
sx = X
sy = Y
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then

With Me
.Move .Left + (X - sx), .Top + (Y - sy)
ox = .Left
oy = .Top
End With
End If

End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Move ox, oy
End Sub
回复
gameboy999 2001-07-27
to DevilXelloss:
模拟发送这种消息有个很大的弱点,就是如果窗体比较大的话,则往上拖动会拖不上去~~
因为它是模拟Caption拖动的消息,而Caption在最上面...

MouseMove的效果会颤抖? 真奇怪?试试GetCursor 在ClientToScreen一下,再来做
回复
发帖
VB基础类
创建于2007-09-28

7476

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2001-07-27 12:46
社区公告
暂无公告