UndoContext.IsOpen 属性

定义

获取指示撤消操作当前是否生效,或是否打开了解决方案的值。

public:
 property bool IsOpen { bool get(); };
public:
 property bool IsOpen { bool get(); };
[System.Runtime.InteropServices.DispId(8)]
public bool IsOpen { [System.Runtime.InteropServices.DispId(8)] get; }
[<System.Runtime.InteropServices.DispId(8)>]
[<get: System.Runtime.InteropServices.DispId(8)>]
member this.IsOpen : bool
Public ReadOnly Property IsOpen As Boolean

属性值

Boolean

一个布尔值,该值指示 true 撤消操作是否有效,或者解决方案是否已打开( false 如果没有)。

属性

示例

Sub IsOpenExample(ByVal dte As DTE2)  

    ' Create a new text file.  
    dte.ItemOperations.NewFile()  

    Dim doc As TextDocument = _  
        CType(dte.ActiveDocument.Object("TextDocument"), TextDocument)  
    Dim done As Boolean = False  

    Do While Not done  
        If dte.UndoContext.IsOpen = False Then  
            Try  
                dte.UndoContext.Open("Insert 10 Lines")  

                ' Insert 10 lines of text into the new document.  
                Dim point As EditPoint = doc.StartPoint.CreateEditPoint  
                Dim i As Integer  

                For i = 1 To 10  
                    point.Insert("This is a test." & vbCrLf)  
                Next  

                done = True  
            Catch  
            Finally  
                If done Then dte.UndoContext.Close()  
            End Try  
        End If  
    Loop  

End Sub  
public void IsOpenExample(DTE2 dte)  
{  
    // Create a new text file.  
    dte.ItemOperations.NewFile(@"General\Text File", "",   
        Constants.vsViewKindPrimary);  

    TextDocument doc =   
        (TextDocument)dte.ActiveDocument.Object("TextDocument");  
    bool done = false;  

    while (!done)  
    {  
        if (!dte.UndoContext.IsOpen)  
        {  
            try  
            {  
                dte.UndoContext.Open("Insert 10 Lines", false);  

                // Insert 10 lines of text into the new document.  
                EditPoint point = doc.StartPoint.CreateEditPoint();  

                for (int i = 0; i < 10; ++i)  
                    point.Insert("This is a test.\n");  

                done = true;  
            }  
            catch  
            {  
            }  
            finally  
            {  
                if (done) dte.UndoContext.Close();  
            }  
        }  
    }  
}  

注解

如果对象处于打开状态,则撤消操作有效 UndoContext

打开的解决方案不一定有解决方案 ( .sln) 文件,因为它可能尚未保存。

适用于