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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219

4 Answers4

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;
    }
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
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
Chris
  • 1,101
  • 8
  • 13
  • 1
    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). – webjprgm Dec 23 '16 at 16:55
  • 1
    This interface is available here: https://msdn.microsoft.com/en-us/library/microsoft.internal.visualstudio.shell.interop.svscolorthemeservice(v=vs.110).aspx – JoshVarty May 24 '17 at 22:11
  • Where did _serviceProvider come from? – sean Aug 07 '17 at 08:17
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.

Security Hound
  • 2,577
  • 3
  • 25
  • 42
  • 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. – Daniel Peñalba Jun 12 '12 at 08:21
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

Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121