共用方式為


UndoContext.SetAborted 方法

捨棄自開啟 UndoContext 物件後所有針對參與開啟文件進行的變更。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
Sub SetAborted
void SetAborted()
void SetAborted()
abstract SetAborted : unit -> unit
function SetAborted()

備註

SetAborted 設定開啟之 UndoContext 物件的 IsAborted 屬性為 true。 當發生這種情況時,從開啟 UndoContext 物件開始到 UndoContext 物件關閉為止,所有針對參與文件進行的變更都會被捨棄。

範例

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

   ' Check to see if UndoContext object is already open.
   If DTE.UndoContext.IsOpen = True Then
      bIsOpen = True
   Else
      ' Open the UndoContext object to track changes.
      DTE.UndoContext.Open("RemoveNewLines", False)
   End If
   MsgBox("Current IsAborted value: " & DTE.UndoContext.IsAborted)

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

   ' Check to see if you want to discard changes.
   strAnswer = MsgBox("Do you want to discard all changes made?", vbYesNo & vbQuestion)
   If strAnswer = True Then
      DTE.UndoContext.SetAborted()
      MsgBox("Current IsAborted value: " & DTE.UndoContext.IsAborted)
   End If

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

.NET Framework 安全性

請參閱

參考

UndoContext 介面

EnvDTE 命名空間