vb编程中想点击鼠标左键拖动控件text1在form1窗体上移动 编码怎么写呀,求高手指点。

2024-12-14 10:49:14
推荐回答(2个)
回答1:

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 HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ncl As Long
Dim rel As Long
If Button = 1 Then
Dim i As Integer

i = ReleaseCapture()
ncl = SendMessage(Text1.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If

End Sub

回答2:

楼上的代码适用于任何运行时可见的控件吗