Freigeben über


How to: Use Text Markers

Text markers can be applied to edit a IVsTextBuffer object.

Procedures

To apply text markers

  1. Obtain an instance of the IVsTextManager class.

    Hinweis

    The core editor automatically applies standard text markers to any document that it is editing, and it should not be necessary to apply standard text markers explicitly.

  2. Obtain a marker type ID of the marker you are interested in by calling the GetRegisteredMarkerTypeID method with the GUID of the text marker you wish to work with.

    Hinweis

    Do not use the GUID of the VSPackage or of the service that provides the text marker.

  3. Use the marker type ID obtained by calling the GetRegisteredMarkerTypeID method as a parameter to call the CreateLineMarker method or the CreateStreamMarker method to apply a text marker to a given region of text.

To add features to text markers

  1. It may be desirable to add additional features to a text marker, such as tool tips, a special context menu, or handler for special circumstances. To do so:

  2. Create an object implementing the IVsTextMarkerClient interface.

  3. If additional functionality is desired, implement the IVsTextMarkerClientEx, and the IVsTextMarkerClientAdvanced interfaces on the same object that implements the IVsTextMarkerClient interface.

  4. Pass the IVsTextMarkerClient interface that you create, to the call to the CreateLineMarker method or the CreateStreamMarker method used to apply the text marker to a given region of text.

  5. When adding context menu support to a text marker region it is necessary to create the menu.

    For more information on how to create a context menu see, Context Menus.

  6. The Visual Studio environment calls the methods of the supplied interfaces, such as the GetTipText method, or the ExecMarkerCommand method as needed.

See Also

Tasks

How to: Add Standard Text Markers

How to: Create Custom Text Markers

How to: Implement Error Markers

Other Resources

Using Text Markers with the Legacy API