共用方式為


Find 介面

支援環境中文件或檔案的一般文字 Find 作業。

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

語法

'宣告
<GuidAttribute("40D4B9B6-739B-4965-8D65-692AEC692266")> _
Public Interface Find
[GuidAttribute("40D4B9B6-739B-4965-8D65-692AEC692266")]
public interface Find
[GuidAttribute(L"40D4B9B6-739B-4965-8D65-692AEC692266")]
public interface class Find
[<GuidAttribute("40D4B9B6-739B-4965-8D65-692AEC692266")>]
type Find =  interface end
public interface Find

Find 類型會公開下列成員。

屬性

  名稱 描述
公用屬性 Action 取得或設定如何尋找,例如尋找下一個、全部尋找、取代和尋找等。
公用屬性 Backwards 取得或設定值,指出是否從目前位置向後執行搜尋。
公用屬性 DTE 取得最上層的擴充性物件。
公用屬性 FilesOfType 取得或設定所要搜尋檔案的副檔名。
公用屬性 FindWhat 取得或設定要尋找的文字或模式比對。
公用屬性 KeepModifiedDocumentsOpen 取得或設定值,指出在 Replace 作業之後已修改的文件是否仍保開啟。
公用屬性 MatchCase 取得或設定值,指出搜尋是否區分大小寫。
公用屬性 MatchInHiddenText 取得或設定值,指出搜尋是否包括隱藏文字。
公用屬性 MatchWholeWord 取得或設定值,指出搜尋是否僅為全字符合。
公用屬性 Parent 取得 Find 物件的直屬父物件。
公用屬性 PatternSyntax 取得或設定語法,用以指定搜尋模式。
公用屬性 ReplaceWith 取得或設定取代作業的取代文字。
公用屬性 ResultsLocation 取得或設定在大量搜尋作業中顯示結果的位置。
公用屬性 SearchPath 取得或設定要用在檔案中尋找作業的目錄清單。
公用屬性 SearchSubfolders 取得或設定值,指出是否在 Search 作業中包含子資料夾。
公用屬性 Target 取得或設定搜尋作業的目標,例如所有開啟的文件、檔案、作用中文件等。

回頁首

方法

  名稱 描述
公用方法 Execute 依據 Find 物件設定的選項執行搜尋。
公用方法 FindReplace 依據方法的引數執行尋找 (Find) 或取代 (Replacement) 作業,而不影響針對 Find 設定的選項。

回頁首

備註

Find 物件可讓您在支援這類作業的環境 (例如程式碼編輯器) 中搜尋和取代文字。

其主要目的是供巨集錄製。 編輯器的巨集錄製機制使用的是 Find 而不是 TextSelection.FindPattern,如此一來,您可以探索全域尋找功能,而且相較於使用 TextSelection 物件進行像是「檔案中尋找」 (Find-in-Files) 的作業,這種機制更為有用。

Visual Studio 環境有一個能讓所有提供搜尋能力的工具共用的全域尋找狀態。 例如,所有 Visual Studio 項目會共用工作階段中的搜尋模式記錄,以及下一個針對開啟文件的 Find 作業是要向前或是向後。 Find 物件的屬性會與全域尋找狀態互動並且追蹤它。 當您設定 Find 物件上的屬性時,您也設定了全域尋找狀態。 如果使用者透過環境執行 Find 作業,則 Find 物件會反映他們所執行的搜尋種類。 由於 Automation 程式碼與環境的 UI 執行緒同步執行,您不需在呼叫 Execute 之前設定某些屬性並讓使用者進行搜尋。

Execute 方法根據 Find 物件的設定執行 Find 作業。 您也可以傳遞引數給 FindReplace 方法執行搜尋,而不影響全域尋找狀態。 Automation 用戶端必須能執行搜尋,而不影響全域尋找狀態或干擾到使用者的環境狀態模型。

範例

Sub FindExample()
   Dim objTextDoc As TextDocument
   Dim objEditPt As EditPoint
   Dim iCtr As Integer
   Dim objFind As Find

   ' Create a new text file.
   DTE.ItemOperations.NewFile("General\Text File")

   ' Get a handle to the new document and create an EditPoint.
   objTextDoc = DTE.ActiveDocument.Object("TextDocument")
   objEditPt = objTextDoc.StartPoint.CreateEditPoint
   objFind = objTextDoc.DTE.Find

   ' Insert ten lines of text.
   For iCtr = 1 To 10
      objEditPt.Insert("This is a test." & Chr(13))
   Next iCtr

   ' Set the find options.
   objFind.Action = vsFindAction.vsFindActionReplaceAll
   objFind.Backwards = False
   objFind.FilesOfType = "*.txt"
   objFind.FindWhat = "test"
   objFind.KeepModifiedDocumentsOpen = True
   objFind.MatchCase = False
   objFind.MatchInHiddenText = False
   objFind.MatchWholeWord = True
   objFind.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
   objFind.ReplaceWith = "NEW THING"
   objFind.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
   objFind.SearchPath = "c:\temp"
   objFind.SearchSubfolders = False
   objFind.Target = vsFindTarget.vsFindTargetCurrentDocument
   ' Perform the Find operation.
   objFind.Execute()
End Sub

請參閱

參考

EnvDTE 命名空間