Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current used color theme of Visual Studio

I'm creating my own IntelliSense Presenter, since Visual Studio2012 support change theme, so I want my background color of the presenter can be auto-changed when the theme been changed. Is there a way to track the theme changes event, or get the current color theme of the Visual Studio?

like image 911
Allen4Tech Avatar asked Apr 10 '13 08:04

Allen4Tech


1 Answers

For VS 2015 this has changed, the solution @Matze has still works but you need to update the GetThemeId() function to check for the version and if it's 14.0 (VS2015) look in a different place in the registry. The way the value is stored has changed also, it's still a string but now contains other values seperated by a '*'. The theme guid is the last value in the list.

if (version == "14.0")
{
   string keyName = string.Format(@"Software\Microsoft\VisualStudio\{0}\ApplicationPrivateSettings\Microsoft\VisualStudio", version);

   using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName))
   {
      if (key != null)
      {
          var keyText = (string)key.GetValue("ColorTheme", string.Empty);

              if (!string.IsNullOrEmpty(keyText))
              {
                  var keyTextValues = keyText.Split('*');
                  if (keyTextValues.Length > 2)
                  {
                       return keyTextValues[2];
                  }
              }
      }
   }

   return null;
}
like image 53
Frank Avatar answered Sep 28 '22 11:09

Frank