• 公共事件,修改主窗体和子窗体的(主题)样式


    主窗体修改主题样式时,同时修改子窗体的主题样式

    系统展示效果:

    一、项目结构

    二、代码分析

      SetAllFormStyle 界面对象参数

      

      

        /// <summary>
        /// 编写:yj
        /// 日期:2014-08-14
        /// 描述:系统界面参数
        /// </summary>
        public class SetAllFormStyle: System.EventArgs
        {
            public C1.Win.C1Ribbon.VisualStyle autoStyle { get; set; }
        }
    

       CommonStyle 全部公共对象

        /// <summary>
        /// 编写:yj
        /// 日期:2014-08-14
        /// 功能:公共静态事件
        /// </summary>
        public static class CommonStyle
        {
            public static C1.Win.C1Ribbon.VisualStyle AllFormSytle = C1.Win.C1Ribbon.VisualStyle.Office2007Blue;
    
            public static event EventHandler<SetAllFormStyle> RFIDReaderClick;
    
            public static void OnRFIDReaderClick(object sender, SetAllFormStyle e)
            {
                if (RFIDReaderClick != null)
                {
                    RFIDReaderClick(sender, e);
                }
            }
        }
    

      BaseForm.cs 基类文件

      

            private void BaseFrom_Load(object sender, EventArgs e)
            {
                CommonStyle.RFIDReaderClick += new EventHandler<SetAllFormStyle>(CommonStyle_RFIDReaderClick);
            }
    
            void CommonStyle_RFIDReaderClick(object sender, SetAllFormStyle e)
            {
                this.VisualStyle = e.autoStyle;
            }
    

       说明:在load方法中,注册公共事件。

      

      

      Form1.cs为设置窗体样式窗体

            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (comboBox1.Text == "Office2010Blue")
                {
                    this.VisualStyle = C1.Win.C1Ribbon.VisualStyle.Office2010Blue;
                }
                else if (comboBox1.Text == "Office2010Silver")
                {
                    this.VisualStyle = C1.Win.C1Ribbon.VisualStyle.Office2010Silver;
                }
                else if (comboBox1.Text == "Office2010Black")
                {
                    this.VisualStyle = C1.Win.C1Ribbon.VisualStyle.Office2010Black;
                }
                else if (comboBox1.Text == "Office2007Blue")
                {
                    this.VisualStyle = C1.Win.C1Ribbon.VisualStyle.Office2007Blue;
                }
    
                SetAllFormStyle safs = new SetAllFormStyle();
                safs.autoStyle = this.VisualStyle;
                CommonStyle.OnRFIDReaderClick(sender, safs);
            }
    

         From2,Form3所有窗体都继承BaseForm,这样就可以实现,修改Form1的主题时,所有窗体的主题样式都改变了。

      

  • 相关阅读:
    poj 2337 欧拉回路输出最小字典序路径 ***
    hdu 4831
    hdu 4832 dp ***
    hdu 4833 离散化+dp ****
    hdu 4006 优先队列 2011大连赛区网络赛F **
    hdu 4005 双联通 2011大连赛区网络赛E *****
    hdu 4004 二分 2011大连赛区网络赛D
    hdu 4003 树形dp+分组背包 2011大连赛区网络赛C
    hdu 4002 欧拉函数 2011大连赛区网络赛B
    跨域经验总结
  • 原文地址:https://www.cnblogs.com/ancient-sir/p/3912963.html
Copyright © 2020-2023  润新知