Getting Font and Color Information for Text Colorization

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

The process that renders or displays colorized text in user interface (UI) elements depends on the type of project, its technology, and developer preferences. The Fonts and Colors property page stores the settings.

Most implementations that display colorized text need the T:Microsoft.VisualStudio.Shell.Interop.IVsFontAndColorDefaults and associated interfaces for presenting, retrieving, and storing text display settings.

Note

When customizing the core editor (which supports the Text EditorCategory), it is strongly recommended that you use the coloring technology in the language service. For more information, see Font and Color Overview.

Getting Default Font and Color Information

All the Fonts and Colors settings of any window displaying text should be specified in the Display Items of one Category. For more information, see Fonts and Colors, Environment, Options Dialog Box.

To colorize, a VSPackage must obtain current Fonts and Colors settings. A VSPackage can accomplish this in the following ways, depending on its needs:

  • Use the font and color persistence mechanism to retrieve the stored or current state. For more information, see Accessing Stored Font and Color Settings.

  • Use the IVsFontAndColorDefaultsProvider interface of a service providing font and color data to get an instance of IVsFontAndColorDefaults, if the VSPackage is not also the font and color provider.

  • Implement the IVsFontAndColorEvents interface.

    To ensure that the results obtained by polling are up-to date, it may be useful to use the IVsFontAndColorCacheManager interface to determine if an update is needed prior to calling the retrieval methods of the IVsFontAndColorStorage interface.

    After you have obtained font and color information, parse the text to be displayed to identify elements requiring colorization and then display the text in the window using the appropriate fonts and colors.

See Also

IVsFontAndColorDefaultsProvider
IVsFontAndColorDefaults
Using Fonts and Text
Working with Color
GDI (graphics device interface)