代码之家  ›  专栏  ›  技术社区  ›  Gareth Hayter

vsto-MS Office“配色方案”已更改事件

  •  3
  • Gareth Hayter  · 技术社区  · 16 年前

    使用vsto,如何获取MS Office配色方案更改通知?

    3 回复  |  直到 12 年前
        1
  •  5
  •   Michael Regan    16 年前

    希望Office2010有更好的功能。以下是我在Office2007和Word中使用的内容(这不是任何通知,只是要检查的内容):

    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
  •  5
  •   jeffmk    12 年前

    请注意,(当然)这在2013年的办公室中有所改变。应改为使用以下常量:

    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;
    

    请注意,如果从未设置主题,“UI主题”键将不存在。不过,我相信它默认为“0”(白色主题)。

        3
  •  1
  •   iashishi    12 年前

    我有类似于Mike Regan提供的代码。我做的另一件事是运行一个独立的线程,它会每秒检查这个注册表项。每当注册表值更改时,我都会触发一个自定义事件。 我的外接程序中的其余代码处理事件,并更改与此事件处理程序中的新主题相对应的UI元素。