Compartilhar via


How to: Implement the Find and Replace Mechanism

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Visual Studio provides two ways of implementing Find/Replace. One way is to pass a text image to the shell and let it handle searching, highlighting, and replacing text. This allows users to specify multiple text spans. Alternatively, your VSPackage can control this functionality itself. In both cases you must notify the shell 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 or __VSFPROPID. If you are creating a custom editor, you should implement this interface as part of the custom editor class.

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

    If your editor supports text image searching, implement GetSearchImage.

    Otherwise, implement Find and Replace.

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

See Also

IVsFindHelper
IVsFindTarget
Find
GetSearchImage
Replace
__VSPROPID