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

发布: 2009-2-03 10:02  作者: 网络转载  查看: 1373次 共有0条评论

Excel :API基础运用:用滑动鼠标改变UserForm大小

將滑鼠移到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高级编程:API基础运用:用滑动鼠标改变UserForm大小 的评论
最新PPT教程
最新评论
PPT问答