傳回已選擇觸發 MouseDown 或 MouseUp 事件的滑鼠按鍵。 唯讀。
語法
運算式。按鈕
運算式 傳回 MouseEvent 物件的運算式。
傳回值
Long
註解
Button 屬性的可能值可以是 Visio 型別程式庫中 VisKeyButtonFlags 列舉中宣告的任何常數。
範例
這個類別模組會示範如何定義名為 MouseListener 的接收類別。 此類別會聆聽由使用中視窗中的滑鼠動作所引發的事件,並使用 WithEvents 關鍵字宣告 vsoWindow 物件變數。 類別模組也包含 MouseDown、 MouseMove 和 MouseUp 事件的事件處理常式。
若要執行此範例,請在 Microsoft Visual Basic for Applications (VBA) 專案中插入新的類別模組,將其命名為 MouseListener,然後在模組中插入下列程式碼。
Dim WithEvents vsoWindow As Window
Private Sub Class_Initialize()
Set vsoWindow = ActiveWindow
End Sub
Private Sub Class_Terminate()
Set vsoWindow = Nothing
End Sub
Private Sub vsoWindow_MouseDown(ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x As Double, ByVal y As Double, CancelDefault As Boolean)
Debug.Print "Button is: "; Button
End Sub
Private Sub vsoWindow_MouseMove(ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x As Double, ByVal y As Double, CancelDefault As Boolean)
Debug.Print "x-position is "; x
Debug.Print "y-position is "; y
End Sub
Private Sub vsoWindow_MouseUp(ByVal Button As Long, ByVal KeyButtonState As Long, ByVal x As Double, ByVal y As Double, CancelDefault As Boolean)
If Button = 1 Then
Debug.Print "Left mouse button released"
ElseIf Button = 2 Then
Debug.Print "Right mouse button released"
ElseIf Button = 16 Then
Debug.Print "Center mouse button released"
End If
End Sub
然後,在 ThisDocument 專案中插入下列程式碼。
Dim myMouseListener As MouseListener
Private Sub Document_DocumentSaved(ByVal doc As IVDocument)
Set myMouseListener = New MouseListener
End Sub
Private Sub Document_BeforeDocumentClose(ByVal doc As IVDocument)
Set myMouseListener = Nothing
End Sub
儲存文件以初始化類別,然後按一下使用中視窗中的任何位置以觸發 MouseDown 事件。 在 [即時運算] 視窗中,處理常式會列印一個值,這個值代表觸發事件所按下的滑鼠按鈕。
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。