来自MSDN
Find 对象允许您在支持此类操作的环境中(例如代码编辑器)搜索和替换文本。
它主要用于宏录制目的。编辑器的宏记录机制使用 Find 而不是 TextSelection.FindPattern,以便您可以发现全局查找功能,并且因为它通常比使用 TextSelection 对象进行“在文件中查找”等操作更有用。
如果搜索操作是异步的,例如“查找全部”,则当操作完成时会发生FindDone事件。
Sub ActionExample()
Dim objFind As Find = objTextDoc.DTE.Find
' Set the find options.
objFind.Action = vsFindAction.vsFindActionFindAll
objFind.Backwards = False
objFind.FilesOfType = "*.vb"
objFind.FindWhat = "<Variable>"
objFind.KeepModifiedDocumentsOpen = False
objFind.MatchCase = True
objFind.MatchInHiddenText = True
objFind.MatchWholeWord = True
objFind.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
objFind.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
objFind.SearchPath = "c:\<Your>\<Project>\<Path>"
objFind.SearchSubfolders = False
objFind.Target = vsFindTarget.vsFindTargetCurrentDocument
' Perform the Find operation.
objFind.Execute()
End Sub
<System.ContextStaticAttribute()> _
Public WithEvents FindEvents As EnvDTE.FindEvents
Public Sub FindEvents_FindDone(ByVal Result As EnvDTE.vsFindResult, _
ByVal Cancelled As Boolean) _
Handles FindEvents.FindDone
Select Case Result
case vsFindResultFound
'Found!
case else
'Not Found
Ens select
End Sub
Run Code Online (Sandbox Code Playgroud)