Question

Somebody know how can I get the color scheme programatically 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.

Thanks in advance.

Was it helpful?

Solution

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;
    }

OTHER TIPS

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

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top