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

sekfore 2001-07-27 12:46:25
我在做一个程序,想用鼠标可以拖动form。可是由于mouse_move是不断产生的。导致form不断的“颤抖”。请大家帮忙解决啊,谢谢了! :)
...全文
268 11 打赏 收藏 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
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一下,再来做

7,788

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧