Table of contents
TOC
折叠目录
展开目录

Application.EndUndoScope 方法 (Visio)Application.EndUndoScope Method (Visio)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

结束或取消具有唯一范围的事务。Ends or cancels a transaction that has a unique scope.

语法Syntax

表达式EndUndoScope( nScopeIDbCommit )expression . EndUndoScope( nScopeID , bCommit )

表达式_一个表示应用程序对象的变量。_expression A variable that represents an Application object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
nScopeIDnScopeID必需RequiredLongLong要关闭的范围的 ID。The ID of the scope to close.
bCommitbCommit必需RequiredBooleanBoolean该标志指明应在范围内所做的更改被接受 ( True ) 或取消 ( False )。flag indicating that the changes made during the scope should be accepted ( True ) or canceled ( False ).

返回值Return Value

Nothing

注解Remarks

如果您需要知道您接收的事件是否为您启动特定操作的结果,,使用了BeginUndoScopeEndUndoScope方法来包装您的操作。在事件处理程序,使用IsInScope属性来测试是否BeginUndoScope方法返回的作用域 ID 是当前上下文的一部分。请确保已清除了当您接收到具有该 ID ExitScope事件存储从BeginUndoScope属性的作用域 IDIf you need to know whether events you receive are the result of a particular operation that you initiated, use the BeginUndoScope and EndUndoScope methods to wrap your operation. In your event handlers, use the IsInScope property to test whether the scope ID returned by the BeginUndoScope method is part of the current context. Make sure you clear the scope ID you stored from the BeginUndoScope property when you receive the ExitScope event with that ID.

您必须平衡对BeginUndoScope方法调用EndUndoScope方法的调用。如果调用BeginUndoScope方法时,应调用EndUndoScope方法,即构成您的作用域的操作完成。此外,同时对多个文档的操作应稳定在一个范围内,关闭文档可能产生副作用,清除当前打开的范围的撤消信息以及清除撤消和重做堆栈。如果发生这种情况,通过 bCommit = FalseEndUndoScope不会还原撤消信息。You must balance calls to the BeginUndoScope method with calls to the EndUndoScope method. If you call the BeginUndoScope method, you should call the EndUndoScope method as soon as you are done with the actions that constitute your scope. Also, while actions to multiple documents should be robust within a single scope, closing a document may have the side effect of clearing the undo information for the currently open scope as well as clearing the undo and redo stacks. If that happens, passing bCommit = False to EndUndoScope does not restore the undo information.

您还可以使用BeginUndoScopeEndUndoScope的方法将添加到 Microsoft Visio 加载项所定义的操作撤消流。当您从无模式的方案中启动代理程序添加的用户界面或无模式的编程操作的一部分运行时,这非常有用。You can also use the BeginUndoScope and EndUndoScope methods to add an action defined by an add-on to the Microsoft Visio undo stream. This is useful when you are operating from modeless scenarios where the initiating agent is part of an add-on's user interface or a modeless programmatic action.

请注意 大多数 Visio 动作已被包装在内部撤消范围,以便在应用程序运行的加载项不需要调用此方法。Note Most Visio actions are already wrapped in internal undo scopes, so add-ons running within the application do not need to call this method.

如果 Visual Studio 解决方案中包含的Microsoft.Office.Interop.Visio引用,此方法将映射到以下类型:If your Visual Studio solution includes the Microsoft.Office.Interop.Visio reference, this method maps to the following types:

  • Microsoft.Office.Interop.Visio.IVApplication.EndUndoScope (int,布尔值)Microsoft.Office.Interop.Visio.IVApplication.EndUndoScope(int, bool)

示例Example

此示例演示如何使用EndUndoScope方法来结束事务的 Visio 实例具有一个唯一的作用域 ID。This example shows how to use the EndUndoScope method to end a transaction that has a unique scope ID for an instance of Visio.


Private WithEvents vsoApplication As Visio.Application  
Private lngScopeID As Long 

Public Sub EndUndoScope_Example()  

    Dim vsoShape As Visio.Shape  

    'Set the module-level application variable to  
    'trap Application-level events.  
    Set vsoApplication = Visio.Application  

    'Begin a scope and set the module-level variable.  
    lngScopeID = vsoApplication.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.  
    vsoApplication.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
© 2018 Microsoft