VSTO - MS Office 'Color Scheme' changed event

混江龙づ霸主 提交于 2019-12-06 06:29:06

问题


Using VSTO, how can I get notification of changes to the MS Office color scheme?


回答1:


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



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3631461/vsto-ms-office-color-scheme-changed-event

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!