开发者

VSTO - MS Office 'Color Scheme' changed event

开发者 https://www.devze.com 2023-01-14 01:12 出处:网络
Using VSTO, how can I get notification of changes to the MS Office col开发者_高级运维or scheme?Hopefully something better exists with Office 2010. Here\'s what I used for Office 2007 and Word (This is

Using VSTO, how can I get notification of changes to the MS Office col开发者_高级运维or scheme?


Hopefully something better exists with Office 2010. Here's what I used for Office 2007 and Word (This is not a notification in any way, just something to check for):

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


Note that (of course) this has been changed in Office 2013. The following constants should be used instead:

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;

Note that if the theme has never been set, the "UI Theme" key won't exist. I believe it defaults to "0" (White theme), though.


I have code similar to what Mike Regan has provided. One extra thing I do is run a seperate thread which keeps checking this registry entry every second. Whenever, the registry value changes, I trigger a custom event. The rest of the code in my add-in handles the event and changes the UI elements corresponding to the new theme in this event handler.

0

精彩评论

暂无评论...
验证码 换一张
取 消