Application.ExitScope 事件 (Visio)

当内部命令结束时或自动化客户端使用 EndUndoScope 方法退出范围时排队。

语法

表达式ExitScope (应用nScopeIDbstrDescriptionbErrOrCancelled)

expression:表示 Application 对象的变量。

参数

名称 必需/可选 数据类型 说明
应用程序 必需 [IVAPPLICATION] 包含范围的 Microsoft Visio 实例。
nScopeID 必需 Long 描述刚刚结束的操作或 BeginUndoScope 方法返回的范围 ID 的独立于语言的数字。
bstrDescription 必需 字符串 在不同语言版本中会有所不同的操作的文本说明。 包含 Visio 操作的用户界面说明,或传递给 BeginUndoScope 方法的说明。
bErrOrCancelled 必需 Boolean 如果在范围中出现错误或取消了范围,则为 True;如果未出现错误且范围也未被取消,则为 False

备注

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

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

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

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

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

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

如果正在处理此事件,该程序通过 AddAdvise 方法创建的连接接收通知,则 ExitScope 事件是一组所选事件之一,这些事件在 Application 对象的 EventInfo 属性中记录额外信息。

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

对于 ExitScope,如果操作失败或被取消,则 bErrOrCancelled 将不会为零。

示例

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

 
Private WithEvents vsoApplication As Visio.Application 
Private lngScopeID AsLong 
 
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 支持和反馈,获取有关如何接收支持和提供反馈的指南。