Excel VBA高级编程:用滑动鼠标改变UserForm大小

2015-04-13 17:30 阅读 392 次 评论关闭

將滑鼠移到UserForm右下方邊緣處並按滑鼠左鍵不放,可自行拖拉窗體大小
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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTBOTTOMRIGHT = 17       '拖放視窗

Private Sub UserForm_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim lngHwnd As Long

If X >= Me.Width - 10 Then
If Y >= Me.Height - 30 Then
lngHwnd = FindWindow(vbNullString, Me.Caption)
ReleaseCapture
SendMessage lngHwnd, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, ByVal 0&
End If
End If
End Sub

Private Sub UserForm_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If X >= Me.Width - 10 Then
If Y >= Me.Height - 30 Then
Me.MousePointer = fmMousePointerSizeNWSE  '東北與西南向的雙箭號。
End If
Else
Me.MousePointer = fmMousePointerDefault
End If
End Sub

Private Sub UserForm_Resize()
Image1.Width = UserForm1.Width - 20
Image1.Height = UserForm1.Height - 35
End Sub

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:Excel VBA高级编程:用滑动鼠标改变UserForm大小 | 猎微网

评论已关闭!