Search code examples
visual-studio-2022visual-studio-extensions

Possible to get Visual Studio's IDE Colors in Extension?


Is it possible to obtain the currently used colors (not Theme names) being used in the Visual Studio IDE from within a VS Extension? I have an extension in which I would like to list the exact colors for things like text, background of panels, etc.


Solution

  • Yes, you can.

    The crucial thing is the VSColorTheme:

    enter image description here

    You could use this to get the specific color:

    var backgroundColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
    

    The above is just a sample. There are various colors defined in the EnvironmentColors definition:

    enter image description here

    You can develop based on the above official SDK documents I shared.

    You can also refer to this official document:

    https://learn.microsoft.com/en-us/visualstudio/extensibility/ux-guidelines/colors-and-styling-for-visual-studio?view=vs-2022#accessing-the-service