How to: Implement the Find and Replace Mechanism

The Visual Studio IDE provides two methods for implementing Find/Replace. One method is to pass a text image to the IDE and let it handle searching, highlighting, and replacing text. This method allows users to specify multiple text spans. Alternatively, your VSPackage can control this functionality itself. Using either method, you must notify the IDE about the current target and the targets for all open documents.

To implement Find/Replace

  1. Implement the IVsFindTarget interface on one of the objects returned by the frame properties VSFPROPID_DocView or VSFPROPID_DocData.

  2. When a user's document is activated, pass the document's IVsFindTarget into the SEID_FindTarget slot of the selection context.

Robust Programming

Use the GetCapabilities method to specify the options that your VSPackage supports and to indicate whether it implements text image searching.

If your VSPackage supports text image searching, implement GetSearchImage. Otherwise, implement Find and Replace.

If you implement the Find and Replace methods, you can simplify your searching tasks by calling the IVsFindHelper interface.

See Also

Reference

IVsFindHelper

IVsFindTarget

Find

GetSearchImage

Replace

__VSPROPID