Visio) (MouseEvent.Button 属性

返回选择以触发 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 支持和反馈,获取有关如何接收支持和提供反馈的指南。