如何实现运行时拖动控件?

a_geng 2002-05-27 06:28:56
如何实现运行时有设计时拖动控件的功能?
...全文
188 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
crystal_heart 2002-05-27
  • 打赏
  • 举报
回复
在控件的MOUSEDOWN事件里面加入 Control.Drag VbBeginDrag,就那么简单。
IsMe 2002-05-27
  • 打赏
  • 举报
回复
option explicit
dim tX as single
dim tY as singel
private sub Control_mousedown(button as integer,shift as integer,x as single,y as single)
if button=vbleftbutton then
tx=x
ty=y
endif
end sub

private sub control_mousemove(button as integer,shift as integer,x as single,y as single)
if button=vbleftbutton then
if abs(x-tx)>15 or abs(y-ty)>15 then
control.move control.left+x-tx,control.top+y-ty
endif
endif
end sub
pl5th2001 2002-05-27
  • 打赏
  • 举报
回复
Option Explicit

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 Long) As Long

Const HTCAPTION = 2
Const WM_NCLBUTTONDOWN = &HA1

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Command1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0
End If
End Sub
xxlroad 2002-05-27
  • 打赏
  • 举报
回复
'移动 command1 希望对你有点用
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 Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
ReleaseCapture
SendMessage Command1.hWnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0
End If
End Sub

1,451

社区成员

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

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