Table of contents
TOC
折叠目录
展开目录

InvisibleApp.MouseDown 事件 (Visio)InvisibleApp.MouseDown Event (Visio)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

在单击鼠标按钮时,发生此事件。Occurs when a mouse button is clicked.

语法Syntax

专用子_表达式__MouseDown( ByVal 按钮作为 long 类型的值ByVal KeyButtonState 作为长ByVal x 作为双为双 ByVal yByVal CancelDefault 作为布尔值)Private Sub expressionMouseDown( **_ByVal Button As Long** , ByVal KeyButtonState As Long , ByVal x As Double , ByVal y As Double , ByVal CancelDefault As Boolean )

表达式_一个表示InvisibleApp对象的变量。_expression A variable that represents an InvisibleApp object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
按钮Button必需RequiredLongLong按下的鼠标按钮。请参阅“注解”来了解可能的值。The mouse button that was pressed. See Remarks for possible values.
KeyButtonStateKeyButtonState必需RequiredLongLong鼠标按钮以及事件的 Shift 和 Ctrl 键的状态。请参阅“注解”来了解可能的值。The state of the mouse buttons and the SHIFT and CTRL keys for the event. See Remarks for possible values.
xx必需RequiredDoubleDouble鼠标指针的 x 坐标。The x-coordinate of the mouse pointer.
yy必需RequiredDoubleDouble鼠标指针的 y 坐标。The y-coordinate of the mouse pointer.
CancelDefaultCancelDefault必需RequiredBooleanBoolean如果 Microsoft Visio 应处理该消息接收来自此事件;否则为则返回 TrueFalse if Microsoft Visio should process the message it receives from this event; otherwise, True .

注解Remarks

可能的值为_按钮_显示在下表中,并在VisKeyButtonFlags中的 Visio 类型库声明。Possible values for Button are shown in the following table, and are declared in VisKeyButtonFlags in the Visio type library.

* * 常 * *Constant *** * 值 * *Value **
* * visMouseLeft * *visMouseLeft **11
* * visMouseMiddle * *visMouseMiddle **1616
visMouseRightvisMouseRight22

可能的值为_KeyButtonState_可以是下表中所示的值在VisKeyButtonFlags在 Visio 类型库声明的组合。例如,如果_KeyButtonState_返回 9,它表示用户在按 CTRL 的同时单击鼠标左键。Possible values for KeyButtonState can be a combination of the values shown in the following table, which are declared in VisKeyButtonFlags in the Visio type library. For example, if KeyButtonState returns 9, it indicates that the user clicked the left mouse button while pressing CTRL.

* * 常 * *Constant *** * 值 * *Value **
visKeyControlvisKeyControl88
visKeyShiftvisKeyShift44
visMouseLeftvisMouseLeft11
visMouseMiddlevisMouseMiddle1616
visMouseRightvisMouseRight22

如果将_CancelDefault_设置为True ,则 Visio 将不处理单击鼠标按钮时,接收到的消息。If you set CancelDefault to True , Visio will not process the message received when the mouse button is clicked.

与某些其他 Visio 事件,不同MouseDown没有前缀"查询,"但它不过是一个查询事件。也就是说,您可以取消处理MouseDown ,或者通过将_CancelDefault_设置为True ,则发送的消息或者,如果您正在使用VisEventProc方法来处理该事件,返回True 。有关详细信息,请参阅本参考中的VisEventProc方法及其任何查询事件 (例如, QueryCancelSuspend事件) 的主题。Unlike some other Visio events, MouseDown does not have the prefix "Query," but it is nevertheless a query event. That is, you can cancel processing the message sent by MouseDown , either by setting CancelDefault to True , or, if you are using the VisEventProc method to handle the event, by returning True . For more information, see the topics for the VisEventProc method and for any of the query events (for example, the QueryCancelSuspend event) in this reference.

如果您使用 Microsoft Visual Basic 或 Visual Basic for Applications (VBA),则此主题中的语法描述的是一种通用而有效的事件处理方法。If you are using Microsoft Visual Basic or Visual Basic for Applications (VBA), the syntax in this topic describes a common, efficient way to handle events.

如果您想要创建您自己的事件对象,使用添加AddAdvise方法。若要创建一个事件对象,运行加载项,请使用Add方法,应用到事件列表集合。若要创建一个事件对象,该对象接收通知,请使用AddAdvise方法。若要查找您想要创建的事件的事件代码,请参阅事件代码If you want to create your own Event objects, use the Add or AddAdvise method. To create an Event object that runs an add-on, use the Add method as it applies to the EventList collection. To create an Event object that receives notification, use the AddAdvise method. To find an event code for the event you want to create, seeEvent codes.

示例Example

此类模块显示了如何定义一个名为MouseListener侦听事件触发的活动窗口中的鼠标操作的接收器类。它通过使用WithEvents关键字声明对象变量_vsoWindow_ 。类模块还包含MouseDownMouseMove ,以及MouseUp事件的事件处理程序。This class module shows how to define a sink class called MouseListener that listens for events fired by mouse actions in the active window. It declares the object variable vsoWindow by using the WithEvents keyword. The class module also contains event handlers for the MouseDown , MouseMove , and MouseUp events.

若要运行此示例,在 VBA 项目中插入一个新的类模块,将它命名为MouseListener ,在模块中插入以下代码。To run this example, insert a new class module in your VBA project, name it MouseListener , and insert the following code in the module.

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

然后,本文档项目中插入以下代码。Then, insert the following code in the ThisDocument project.

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事件在活动窗口中单击任意位置。在立即窗口中,处理程序打印为触发事件而单击的鼠标按钮的名称。Save the document to initialize the class, and then click anywhere in the active window to fire a MouseDown event. In the Immediate window, the handler prints the name of the mouse button that was clicked to fire the event.

© 2018 Microsoft