Application.EnterScope 事件 (Visio)

在内部命令开始或自动化客户端使用 BeginUndoScope 方法打开范围时进行排队。

语法

表达式EnterScope (应用nScopeIDbstrDescription)

expression:表示 Application 对象的变量。

参数

名称 必需/可选 数据类型 说明
应用程序 必需 [IVAPPLICATION] 包含范围的 Microsoft Visio 实例。
nScopeID 必需 Long 对刚刚结束的操作进行描述的独立于语言的数字,或由 BeginUndoScope 方法返回的范围 ID。
bstrDescription 必需 字符串 在不同语言版本中会有所不同的操作的文本说明。 包含 Visio 操作的用户界面说明,或传递给 BeginUndoScope 方法的说明。

备注

在 Visio 操作的情况下返回的 nScopeID 值等效于以 visCmd 开头的与命令相关的常量。

如果您使用 Microsoft Visual Basic 或 Visual Basic for Applications (VBA),则此主题中的语法描述的是一种通用而有效的事件处理方法。

如果要创建自己的 Event 对象,请使用 AddAddAdvise 方法。

若要创建可运行加载项的 Event 对象,请使用 Add 方法,因为它适用于 EventList 集合。

若要创建可接收通知的 Event 对象,请使用 AddAdvise 方法。

若要查找要创建的事件的事件代码,请参阅事件代码

如果您从中处理此事件的程序可通过使用 AddAdvise 方法创建的连接接收通知,则 EnterScope 事件是可在 Application 对象的 EventInfo 属性中记录附加信息的一组选定事件之一。

EventInfo 属性返回 bstrDescription,如前所述。 此外,VisEventProcvarMoreInfo 参数包含格式如下的字符串:[<nScopeID>;<bErrOrCancelled>;<bstrDescription>;<nHwndContext>],其中 nHwndContext 是作为命令上下文的窗口 (HWND) 窗口的窗口句柄;nHwndContext 可以为 0。

对于 EnterScopebErrOrCancelled 将始终等于零。

示例

此示例说明如何使用 EnterScope 事件。 该示例确定对处理 CellChanged 事件的过程的调用是否在特定范围内;即是否在该范围的 EnterScopeExitScope 事件之间发生调用。

Private WithEvents vsoApplication As Visio.Application 
 
Private lngScopeID As Long 
 
Public Sub Scope_Example() 
 
 Dim vsoShape As Visio.Shape 
 
 'Set the module-level application variable to 
 'trap application-level events. 
 Set vsoApplication = Application 
 
 'Begin a scope. 
 lngScopeID = Application.BeginUndoScope("Draw Shapes") 
 
 'Draw three shapes. 
 Set vsoShape = ActivePage.DrawRectangle(1, 2, 2, 1) 
 ActivePage.DrawOval 3, 4, 4, 3 
 ActivePage.DrawLine 4, 5, 5, 4 
 
 'Change a cell (to trigger a CellChanged event). 
 vsoShape.Cells("Width").Formula = 5 
 
 'End and commit this scope. 
 Application.EndUndoScope lngScopeID, True 
 
End Sub 
 
Private Sub vsoApplication_CellChanged(ByVal Cell As IVCell) 
 
 'Check to see if this cell change is the result of something 
 'happening within the scope. 
 If vsoApplication.IsInScope(lngScopeID) Then 
 Debug.Print Cell.Name & " changed in scope "; lngScopeID 
 End If 
 
End Sub 
 
Private Sub vsoApplication_EnterScope(ByVal app As IVApplication, _ 
 ByVal nScopeID As Long, _ 
 ByVal bstrDescription As String) 
 
 If vsoApplication.CurrentScope = lngScopeID Then 
 Debug.Print "Entering my scope " & nScopeID 
 Else 
 Debug.Print "Enter Scope " & bstrDescription & "(" & nScopeID & ")" 
 End If 
 
End Sub 
 
Private Sub vsoApplication_ExitScope(ByVal app As IVApplication, _ 
 ByVal nScopeID As Long, _ 
 ByVal bstrDescription As String, _ 
 ByVal bErrOrCancelled As Boolean) 
 
 If vsoApplication.CurrentScope = lngScopeID Then 
 Debug.Print "Exiting my scope " & nScopeID 
 Else 
 Debug.Print "Exit Scope " & bstrDescription & "(" & nScopeID & ")" 
 End If 
 
End Sub

支持和反馈

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