Visio (Window.MouseUp 事件)

會在放開滑鼠按鈕時發生。

語法

運算式MouseUp (ButtonKeyButtonStatexyCancelDefault)

表達 代表 Window 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Button 必要 Long 放開的滑鼠按鈕。 可能的值會在 VisKeyButtonFlags中宣告。
KeyButtonState 必要 Long 滑鼠按鍵的狀態,以及事件的 Shift 和 Ctrl 鍵。 可能的值可以是 VisKeyButtonFlags中所宣告值的組合。 例如,如果 KeyButtonState 傳回 9,表示使用者按下 Ctrl 時按一下滑鼠左鍵。
x 必要 雙精確度 滑鼠指標的 X 座標。
y 必要 雙精確度 滑鼠指標的 Y 座標。
CancelDefault 必要 布林值 False 表示 Microsoft Visio 應該處理從這個事件收到的訊息,否則為 True

註解

如果您將 CancelDefault 設為 True,Visio 將不會處理按下滑鼠按鈕時所接收的訊息。

不同于某些其他 Visio 事件, MouseUp 沒有前置詞 Query,但它仍然是查詢事件。 也就是說,您可以取消處理 MouseUp所傳送的訊息,方法是將 CancelDefault 設定為 True,或者,如果您使用 VisEventProc 方法來處理事件,則傳回 True。 如需詳細資訊,請參閱本自動化參考中有關 VisEventProc 方法以及任何查詢事件 (例如 QueryCancelSuspend 事件) 的主題。

如果您是使用 Microsoft Visual Basic 或 Visual Basic for Applications (VBA),則本主題中的語法會描述有效處理事件的常用方式。

如果您想要建立自己的 Event 物件,請使用 AddAddAdvise 方法。

若要建立可以執行附加元件的 Event 物件,可使用 Add 方法,因為它可適用於 EventList 集合。

若要建立用於接收通知的 Event 物件,則使用 AddAdvise 方法。

若要尋找您要建立之事件的事件代碼,請參閱 事件代碼

範例

這個類別模組會示範如何定義名為 MouseListener 的接收類別。 此類別會聆聽由使用中視窗中的滑鼠動作所引發的事件,並使用 WithEvents 關鍵字宣告 vsoWindow 物件變數。 類別模組也包含 MouseDownMouseMoveMouseUp 事件的事件處理常式。

若要執行此範例,請在 VBA 專案中插入新的類別模組、將它命名為 MouseListener,然後在模組中插入下列程式碼。

Dim WithEvents vsoWindow As Visio.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) 
 
 If Button = 1 Then 
 
 Debug.Print "Left mouse button clicked" 
 
 ElseIf Button = 2 Then 
 
 Debug.Print "Right mouse button clicked" 
 
 ElseIf Button = 16 Then 
 
 Debug.Print "Center mouse button clicked" 
 
 End If 
 
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

儲存檔以初始化 類別,然後按一下使用中視窗中的任何位置以引發 MouseUp 事件。 在 [即時運算] 視窗中,處理常式會列出已經按下以引發事件的滑鼠按鈕名稱。

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應