/// <summary> /// 刷新样式 /// </summary> private void ThemeRefresh() { //循环所有页面已经存在的控件 foreach (var item in this.Container.Components) { try { System.Windows.Forms.Control con = (System.Windows.Forms.Control)item; Assembly assembly = Assembly.GetExecutingAssembly(); Object obj = assembly.CreateInstance(con.GetType().FullName); //判断控件基类是否来自UCControlBase if (typeof(UCControlBase).IsAssignableFrom(obj.GetType())) { //根据对应的主题找到实现类 IControlTheme uct = (IControlTheme)assembly.CreateInstance("HZH_Controls.Theme." + this._ThemeType); uct.ControlTheme(con); } } catch { } } }
private void UCControlBase_Load(object sender, EventArgs e) { string ThemeType = ""; /* * 新拖动的控件为了继承已经选择的主题,需要再加载后根据主题绘制属性 * 1.循环所有页面控件,找到样式控件 * 2.得到样式控件主题 * 3.调用实现类 */ try { //1.循环所有页面控件,找到样式控件 foreach (var item in this.Container.Components) { if (ThemeType == "") { try { HZH_Controls.Theme.UCTheme con = (HZH_Controls.Theme.UCTheme)item; //2.得到样式控件主题 ThemeType = con.ThemeType.ToString(); break; } catch { } } } } catch { } if (ThemeType != "") { // 3.调用实现类 Assembly assembly = Assembly.GetExecutingAssembly(); IControlTheme uct = (IControlTheme)assembly.CreateInstance("HZH_Controls.Theme." + ThemeType); uct.ControlTheme(this); } }