Application.MouseMove 事件 (Visio)

在移动鼠标时发生。

语法

表达式MouseMove (按钮KeyButtonStatexyCancelDefault)

expression:表示 Application 对象的变量。

参数

名称 必需/可选 数据类型 说明
Button 必需 Long 单击的鼠标按钮。 可能的值在 VisKeyButtonFlags 中声明。
KeyButtonState 必需 Long 事件的鼠标按钮以及 Shift 和 Ctrl 键的状态。 可能的值可以是 VisKeyButtonFlags 中声明的值的组合。 例如,如果 KeyButtonState 返回 9,则表示用户在按 Ctrl 时单击了鼠标左键。
x 必需 Double 鼠标指针的 x 坐标。
y 必需 Double 鼠标指针的 y 坐标。
CancelDefault 必需 Boolean 如果 Microsoft Visio 应处理从此事件接收的消息,则为 False;否则为 True

备注

如果将 CancelDefault 设置为 True,Visio 将不对单击鼠标按钮时所接收的消息进行处理。

与其他一些 Visio 事件不同, MouseMove 没有前缀 Query,但它仍然是查询事件。 也就是说,可以通过将 CancelDefault 设置为 True 来取消处理 MouseMove 发送的消息,或者,如果使用 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

保存该文档以初始化类,然后在活动窗口中快速移动鼠标,以触发一系列 MouseMove 事件。 在“立即”窗口中,处理程序将输出 x 和 y 位置值对列表,每个值对分别对应于触发 MouseMove 事件时的鼠标位置。

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。