Getting Font and Color Information for Text Colorization

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Getting Font and Color Information for Text Colorization.

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.

System_CAPS_ICON_note.jpg 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.

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:

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.

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

Show: