Office 2010 AddIn 开发 - 我可以从代码隐藏中读取用户正在使用的主题吗?

发布于 2024-10-11 11:11:32 字数 66 浏览 0 评论 0原文

PowerPoint 2010 提供三种默认主题:银色、黑色和蓝色。是否可以从代码隐藏中检查用户当前正在使用哪个主题?

PowerPoint 2010 comes with three default themes, silver, black and blue. Is it possible to check which theme the user is currently using from code-behind?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一笑 2024-10-18 11:11:32

我使用此代码根据设置的主题设置界面的颜色。

public static class LFTheme 
    {
        const int ThemeClassic = 0;
        const int ThemeBlue = 1;
        const int ThemeSilver = 2;
        const int ThemeBlack = 3;

        public static int Theme { get; set; }
        public static Color BackColor { get; set; }
        public static Color ForeColor { get; set; }
        public static Color ForeColorLight { get; set; }
        public static Color ForeColorDark { get; set; }
        public static Color TextColor { get; set; }
        public static System.Drawing.Font Font { get; set; }

        public static Excel.Application ExcelApp { get; set; }
        public static Double ExcelVersion { get; set; }

        static LFTheme()
        {
            InitLook();
        }


     public static void InitLook()
            {
                const string OfficeCommonKey = @"Software\Microsoft\Office\{0:0.0}\Common";
                const string OfficeThemeValueName = "Theme";

                Theme = 0;
                BackColor = System.Windows.Forms.Control.DefaultBackColor;
                ForeColor = System.Drawing.SystemColors.Control;
                ForeColorLight = System.Drawing.SystemColors.ControlLight;
                ForeColorDark = System.Drawing.SystemColors.ControlDark;
                TextColor = System.Drawing.SystemColors.ControlText;
                Font = System.Windows.Forms.Control.DefaultFont;

                if (ExcelVersion<12.0)
                    return;

                using (RegistryKey key = Registry.CurrentUser.OpenSubKey(String.Format(OfficeCommonKey, ExcelVersion), false))
                {
                    try
                    {
                        Theme = (int)key.GetValue(OfficeThemeValueName);
                    }
                    catch (Exception ex)
                    {
                        Theme = ThemeClassic;
                        if (ExcelVersion >= 12.0)
                        {
                            Theme = ThemeBlue;
                        }
                    }

                    switch (Theme)
                    {
                        case ThemeBlue:
                            BackColor = Color.FromArgb(255, 213, 228, 242);
                            ForeColor = Color.FromArgb(255, 107, 160, 209);
                            ForeColorLight = Color.FromArgb(255, 185, 210, 234);
                            ForeColorDark = Color.FromArgb(255, 87, 149, 204);
                            TextColor = Color.FromArgb(255, 50, 108, 160);
                            Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                            break;

                        case ThemeSilver:
                            BackColor = Color.FromArgb(255, 232, 236, 243);
                            ForeColor = Color.FromArgb(255, 158, 162, 161);
                            ForeColorLight = Color.FromArgb(255, 200, 206, 205);
                            ForeColorDark = Color.FromArgb(255, 128, 133, 131);
                            TextColor = Color.FromArgb(255, 116, 118, 123);
                            Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                            break;

                        case ThemeBlack:
                            BackColor = Color.FromArgb(255, 83, 83, 83);
                            ForeColor = Color.FromArgb(255, 168, 170, 170);
                            ForeColorLight = Color.FromArgb(255, 188, 190, 190);
                            ForeColorDark = Color.FromArgb(255, 148, 150, 150);
                            TextColor = Color.FromArgb(255, 224, 226, 226);
                            Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                            break;

                        default:                    
                            break;
                    }
                }
            }


}

I use this code to setup colours for my interface depending on what theme is set.

public static class LFTheme 
    {
        const int ThemeClassic = 0;
        const int ThemeBlue = 1;
        const int ThemeSilver = 2;
        const int ThemeBlack = 3;

        public static int Theme { get; set; }
        public static Color BackColor { get; set; }
        public static Color ForeColor { get; set; }
        public static Color ForeColorLight { get; set; }
        public static Color ForeColorDark { get; set; }
        public static Color TextColor { get; set; }
        public static System.Drawing.Font Font { get; set; }

        public static Excel.Application ExcelApp { get; set; }
        public static Double ExcelVersion { get; set; }

        static LFTheme()
        {
            InitLook();
        }


     public static void InitLook()
            {
                const string OfficeCommonKey = @"Software\Microsoft\Office\{0:0.0}\Common";
                const string OfficeThemeValueName = "Theme";

                Theme = 0;
                BackColor = System.Windows.Forms.Control.DefaultBackColor;
                ForeColor = System.Drawing.SystemColors.Control;
                ForeColorLight = System.Drawing.SystemColors.ControlLight;
                ForeColorDark = System.Drawing.SystemColors.ControlDark;
                TextColor = System.Drawing.SystemColors.ControlText;
                Font = System.Windows.Forms.Control.DefaultFont;

                if (ExcelVersion<12.0)
                    return;

                using (RegistryKey key = Registry.CurrentUser.OpenSubKey(String.Format(OfficeCommonKey, ExcelVersion), false))
                {
                    try
                    {
                        Theme = (int)key.GetValue(OfficeThemeValueName);
                    }
                    catch (Exception ex)
                    {
                        Theme = ThemeClassic;
                        if (ExcelVersion >= 12.0)
                        {
                            Theme = ThemeBlue;
                        }
                    }

                    switch (Theme)
                    {
                        case ThemeBlue:
                            BackColor = Color.FromArgb(255, 213, 228, 242);
                            ForeColor = Color.FromArgb(255, 107, 160, 209);
                            ForeColorLight = Color.FromArgb(255, 185, 210, 234);
                            ForeColorDark = Color.FromArgb(255, 87, 149, 204);
                            TextColor = Color.FromArgb(255, 50, 108, 160);
                            Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                            break;

                        case ThemeSilver:
                            BackColor = Color.FromArgb(255, 232, 236, 243);
                            ForeColor = Color.FromArgb(255, 158, 162, 161);
                            ForeColorLight = Color.FromArgb(255, 200, 206, 205);
                            ForeColorDark = Color.FromArgb(255, 128, 133, 131);
                            TextColor = Color.FromArgb(255, 116, 118, 123);
                            Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                            break;

                        case ThemeBlack:
                            BackColor = Color.FromArgb(255, 83, 83, 83);
                            ForeColor = Color.FromArgb(255, 168, 170, 170);
                            ForeColorLight = Color.FromArgb(255, 188, 190, 190);
                            ForeColorDark = Color.FromArgb(255, 148, 150, 150);
                            TextColor = Color.FromArgb(255, 224, 226, 226);
                            Font = new System.Drawing.Font("Segoe UI", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
                            break;

                        default:                    
                            break;
                    }
                }
            }


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文