Get the Visual Studio color scheme from a VSPackage
Asked Answered
S

4

7

How can I get the color scheme programmatically using a VSPackage in C#?

I know that I can use IVsUIShell5.GetThemedColor for VS2011, but I don't know how to get it from VS2005, VS2008 or VS2010.

Stavros answered 11/6, 2012 at 14:13 Comment(0)
S
4

There are two ways, using IVSShell and IVSShell2:

    private List<Color> GetColorList1()
    {
        IVsUIShell uiShell = (IVsUIShell)this.GetService(typeof(IVsUIShell));

        List<Color> result = new List<Color>();

        foreach (VSSYSCOLOR vsSysColor in Enum.GetValues(typeof(VSSYSCOLOR)))
        {
            uint win32Color;
            uiShell.GetVSSysColor(vsSysColor, out win32Color);
            Color color = ColorTranslator.FromWin32((int)win32Color);
            result.Add(color);
        }

        return result;
    }

    private List<Color> GetColorList2()
    {
        IVsUIShell2 uiShell = (IVsUIShell2)this.GetService(typeof(IVsUIShell2));

        List<Color> result = new List<Color>();

        foreach (__VSSYSCOLOREX vsSysColor in Enum.GetValues(typeof(__VSSYSCOLOREX)))
        {
            uint win32Color;
            uiShell.GetVSSysColorEx((int)vsSysColor, out win32Color);
            Color color = ColorTranslator.FromWin32((int)win32Color);
            result.Add(color);
        }

        return result;
    }
Stavros answered 12/6, 2012 at 17:15 Comment(0)
C
2

I found a solution:

[Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
interface SVsColorThemeService
{
}

then:

dynamic colorThemeService = _serviceProvider.GetService(typeof(SVsColorThemeService));
Guid id = colorThemeService.CurrentTheme.ThemeId;
// should be one of the Microsoft.VisualStudio.Shell.KnownColorThemes
Circumnavigate answered 2/4, 2016 at 3:56 Comment(3)
It is a little disconcerting to use an interface with no members and no IntelliSense help, but this appears to work for me (VS 2015).Ploch
This interface is available here: msdn.microsoft.com/en-us/library/…Series
Where did _serviceProvider come from?Halitosis
G
0

I realized this was actually an answer.

What you want to retrieved is not exposed by the IVsUIShell4 and below

I would like to add that to my knowlege Visual Studio 2005-2010 do not even have themes per say. At the very least Visual Studio 2012 changes this mechanic. You could load the settings file but they were not themes per say.

Microsoft.VisualStudio.Shell.Interop does not even have the require enumeration.

Guzman answered 11/6, 2012 at 18:39 Comment(1)
Yes, but I know that you can change the VS2010 theme, so the theme must be in any place, the registry a config file? That's my question.Eurhythmy
L
0

I guess if no siutable API there, you could always do that directly in registry.

Also you might wnat to look at these link: How to: Access the Built-in Fonts and Color Scheme

Lita answered 13/6, 2012 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.