vb中,如何在运行时用鼠标对控件(如Textbox)进行移动和缩放(即改变大小)操作?

2024-12-29 04:28:20
推荐回答(1个)
回答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
Const WM_SYSCOMMAND = &H112
Const SC_MOVE = &HF010&
Const HTCAPTION = 2
Private Sub MoveWindow(ByVal hwnd As Long)

Dim ret As Long

ReleaseCapture

ret = SendMessage(Text1.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0)
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
MoveWindow hwnd
End Sub