Export (0) Print
Expand All
Cut
Run
Expand Minimize
This topic has not yet been rated - Rate this topic

Close Method (UndoContext Object)

Visual Studio .NET 2003

Ends an undo operation.

[Visual Basic .NET]
Public Sub Close() 
[Visual Basic 6]
Sub Close() 
[C++]
HRESULT __stdcall Close();
[C#]
void Close();
[JScript .NET]
public function Close()

Remarks

If there are pending references to the UndoContext object, then Close aborts the operation and raises an error. An error occurs if the UndoContext object is not open when Close is called.

Example

This example removes all newline characters from a block of selected text:

Sub RemoveNewLines()
   ' Before running, select text in an open document.
   Dim txtSel As TextSelection
   Dim strTS As String, boolWasOpen As Boolean
   txtSel = DTE.ActiveDocument.Selection
   strTS = txtSel.Text

   ' Check to see if UndoContext object is already open.
   If DTE.UndoContext.IsOpen = True Then
      boolWasOpen = True
   Else
      ' Open the UndoContext object to track changes.
      DTE.UndoContext.Open("RemoveNewLines", False)
   End If

   ' Perform search for newline characters and remove them.
   If strTS <> "" Then
      txtSel.Delete()
      strTS = Replace(strTS, vbNewLine, "", Compare:=vbTextCompare)
      txtSel.Insert(strTS)
   End If

   ' If UndoContext was already open, don't close it.
   If boolWasOpen = False Then
      ' Close the UndoContext object to commit the changes.
      DTE.UndoContext.Close()
   End If
End Sub

See Also

Open Method (UndoContext Object)

Applies To: UndoContext Object

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.