Visio) (Application.ExitScope 事件

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

语法

表达式。ExitScope (app, nScopeID, bstrDescription, bErrOrCancelled)

expression:表示 Application 对象的变量。

参数

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

备注

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

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

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

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

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

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

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

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

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

示例

此示例示范如何使用 ExitScope 事件。 此示例确定对处理 CellChanged 事件的过程的调用是否在特定作用域中;也就是说,调用是否发生在该作用域的 EnterScope 和 ExitScope 事件之间。

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