主窗體修改主題樣式時,同時修改子窗體的主題樣式this
系統展現效果:spa
1、項目結構orm
2、代碼分析對象
SetAllFormStyle 界面對象參數blog
/// <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方法中,註冊公共事件。get
Form1.cs爲設置窗體樣式窗體event
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的主題時,全部窗體的主題樣式都改變了。class