'共享模块
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
Dim PrevX As Long, PrevY As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
PrevX = X: PrevY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
If Button = 1 Then
Select Case Me.MousePointer
Case 0
'Me.Move Me.Left + X - PrevX, Me.Top + Y - PrevY
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
Case 7
Me.Height = Y
Case 8
Me.Width = X: Me.Height = Y
Case 9
Me.Width = X
End Select
End If
If Y > Me.ScaleHeight - 120 Then
Me.MousePointer = IIf(X > Me.ScaleWidth - 120, 8, 7)
Else
Me.MousePointer = IIf(X > Me.ScaleWidth - 120, 9, 0)
End If
End Sub
本文介绍了一个使用VBA实现窗体鼠标拖动和调整大小功能的方法。通过声明Windows API函数并利用MouseMove和MouseDown事件,可以实现在不同鼠标指针样式下对窗体进行拖动和调整其高度及宽度。
2041

被折叠的 条评论
为什么被折叠?



