【问题标题】:VSTO - MS Office 'Color Scheme' changed eventVSTO - MS Office“配色方案”更改事件
【发布时间】:2014-09-11 09:28:13
【问题描述】:

使用 VSTO,如何获得 MS Office 颜色方案更改的通知?

【问题讨论】:

    标签: vsto


    【解决方案1】:

    希望 Office 2010 存在更好的东西。这是我用于 Office 2007 和 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】:

      请注意,(当然)这在 Office 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”(白色主题)。

      【讨论】:

      • 在 Office 365 2016 中对我来说:color=1, gray=3, dark=4, white=5
      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2017-12-05
        • 1970-01-01
        • 2016-12-30
        • 2017-10-30
        • 2017-07-13
        • 2013-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多