VSTO event changed - MS Office 'Color Scheme'

Using VSTO, how can I get notified of changes in the color scheme of MS Office?

+3
source share
3 answers

Hope there is something better with Office 2010. Here is what I used for Office 2007 and Word (this is not a notification, just check something):

const string OfficeCommonKey =
  @"Software\Microsoft\Office\12.0\Common";
const string OfficeThemeValueName = "Theme";
const int ThemeBlue = 1;
const int ThemeSilver = 2;
const int ThemeBlack = 3;

using (RegistryKey key = Registry.CurrentUser.OpenSubKey(OfficeCommonKey, false))
{
    int theme = (int)key.GetValue(OfficeThemeValueName,1);

    switch (theme)
    {
        case ThemeBlue:
            //...
            break;
        case ThemeSilver:
            //...
            break;
        case ThemeBlack:
            //...
            break;
        default:
            //...
            break;
   }
}
+5
source

Note that (of course) this was changed in Office 2013. Instead, use the following constants:

const string OfficeCommonKey =
  @"Software\Microsoft\Office\15.0\Common";
const string OfficeThemeValueName = "UI Theme";
const int ThemeWhite = 0;
const int ThemeLightGray = 1;
const int ThemeDarkGray = 2;

Please note that if the theme has never been installed, the "Interface Theme" button will not exist. I believe that it defaults to "0" ("White theme").

+5
source

I have code similar to what Mike Regan provided. Another thing I do is to start a separate thread that checks this registry entry every second. Whenever the registry value changes, I fire a custom event. The rest of the code in my add-in processes the event and modifies the user interface elements corresponding to the new theme in this event handler.

+1
source

Source: https://habr.com/ru/post/1762957/


All Articles