共用方式為


Application.MouseUp 事件 (Visio)

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

語法

表情。滑鼠上 (按鈕KeyButtonStatexy取消預設)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Button 必要 Long 放開的滑鼠按鈕。 可能的值會在 VisKeyButtonFlags 中宣告。
KeyButtonState 必要 Long 滑鼠按鈕的狀態,以及事件的 Shift 和 Ctrl 鍵。 可能的值可以是 VisKeyButtonFlags 中宣告的值組合而成。 例如,如果 KeyButtonState 回傳 9,表示使用者在按下 Ctrl 時同時點擊了滑鼠左鍵。
x 必要 雙精確度 滑鼠指標的 X 座標。
y 必要 雙精確度 滑鼠指標的 Y 座標。
取消違約 必要 布林值 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),則本主題中的語法會描述有效處理事件的常用方式。

如果你想建立自己的 事件 物件,可以使用 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 支援與意見反應