|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Assembly: EnvDTE80 (in envdte80.dll)
/** @attribute GuidAttribute("01568308-5B2A-4F30-8D0A-E10EE0F28F4A") */ public interface Find2 extends Find
Theobject allows you to find and replace text in places of the environment that support such operations, such as the Code editor.
It is intended primarily for macro recording purposes. The editor's macro recording mechanism uses Find rather than TextSelection.FindPattern so that you can discover the global find functionality. Furthermore, it is generally more useful than using theobject for such operations as Find-in-files.
The Visual Studio environment's global find state is shared across all its tools and provides search capabilities. For example, all Visual Studio elements share the history of search patterns used during a session and whether the next Find operation for open documents should be forwards or backwards. The Find object's properties interact with and track the global find state. When you set properties on the Find object, you also set the global find state. If users perform a Find operation through the environment, the Find object reflects the kind of search they performed. Since automation code runs synchronously with the environment's UI thread, you do not need to worry about setting some properties and having the user perform a search before you can call the.
The Execute method performs a Find operation based on the settings of the Find object. You can also pass arguments to themethod to perform a search without affecting the global find state. It is important for automation clients to be able to perform a search without affecting the global find state or interfering with the end user's model of the environment's state.
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