using System; using System.Data; using DevComponents.DotNetBar; namespace MyDotNetBarDemo { /// <summary> /// DotNetBar的使用 /// 需要引入两个DLL(DevComponents.DotNetBar.Design.dll,DevComponents.DotNetBar2.dll)两个【DotNetBar V14破解版】 /// LDH @ 2018-2-5 /// </summary> public partial class FrmMain : Office2007Form { /// <summary> /// 皮肤名称 /// </summary> private readonly string[] _skinNames = { "Office2007Blue", "Office2007Silver", "Office2007Black", "Office2010Silver", "Office2010Blue", "Office2013", "Office2016", "Metro", "VisualStudio2012Dark", "VisualStudio2012Light", "Windows7Blue", "OfficeMobile2014", "VisualStudio2010Blue" }; /// <summary> /// 样式管理器 /// </summary> public StyleManager StyleManager; public FrmMain() { EnableGlass = false; InitializeComponent(); } private void FrmMain_Load(object sender, EventArgs e) { LoadData(); } /// <summary> /// 加载数据 /// </summary> private void LoadData() { Text = @"DotNetBar皮肤"; foreach (var skin in _skinNames) { cboSkins.Items.Add(skin); } dataGridViewX1.AllowUserToAddRows = false; dataGridViewX1.DataSource = null; dataGridViewX1.DataSource = GetDataTable(); } /// <summary> /// 下拉列表选择项发生变化触发的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cboSkins_SelectedIndexChanged(object sender, EventArgs e) { StyleManager = new StyleManager(); var skinName = cboSkins.Text; // 设置皮肤 switch (skinName) { case "Office2007Blue": StyleManager.ManagerStyle = eStyle.Office2007Blue; break; case "Office2007Silver": StyleManager.ManagerStyle = eStyle.Office2007Silver; break; case "Office2007Black": StyleManager.ManagerStyle = eStyle.Office2007Black; break; case "Office2010Silver": StyleManager.ManagerStyle = eStyle.Office2010Silver; break; case "Office2010Blue": StyleManager.ManagerStyle = eStyle.Office2010Blue; break; case "Office2013": StyleManager.ManagerStyle = eStyle.Office2013; break; case "Office2016": StyleManager.ManagerStyle = eStyle.Office2016; break; case "Metro": StyleManager.ManagerStyle = eStyle.Metro; break; case "VisualStudio2012Dark": StyleManager.ManagerStyle = eStyle.VisualStudio2012Dark; break; case "VisualStudio2012Light": StyleManager.ManagerStyle = eStyle.VisualStudio2012Light; break; case "Windows7Blue": StyleManager.ManagerStyle = eStyle.Windows7Blue; break; case "OfficeMobile2014": StyleManager.ManagerStyle = eStyle.OfficeMobile2014; break; case "VisualStudio2010Blue": StyleManager.ManagerStyle = eStyle.VisualStudio2010Blue; break; } } /// <summary> /// 手动创建 DataTable /// </summary> /// <returns></returns> public static DataTable GetDataTable() { var dt = new DataTable(); // Columns dt.Columns.AddRange(new[] { new DataColumn("Id", typeof (int)), new DataColumn("Name", typeof (string)), new DataColumn("Age", typeof (int)), new DataColumn("Address", typeof (string)), new DataColumn("CarNo", typeof (string)) }); // Data Rows var row = dt.NewRow(); row["Id"] = 1; row["Name"] = "Jinger Yan"; row["Age"] = 25; row["Address"] = "江苏南京"; row["CarNo"] = "苏A88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 2; row["Name"] = "Sam Lu"; row["Age"] = 50; row["Address"] = "江苏无锡"; row["CarNo"] = "苏B88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 3; row["Name"] = "Jason Li"; row["Age"] = 28; row["Address"] = "江苏徐州"; row["CarNo"] = "苏C88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 4; row["Name"] = "Tom Wang"; row["Age"] = 18; row["Address"] = "江苏常州"; row["CarNo"] = "苏D88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 5; row["Name"] = "Gloden Jin"; row["Age"] = 28; row["Address"] = "江苏苏州"; row["CarNo"] = "苏E88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 6; row["Name"] = "Jerry Zhao"; row["Age"] = 36; row["Address"] = "江苏南通"; row["CarNo"] = "苏F88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 7; row["Name"] = "Lily Zhou"; row["Age"] = 53; row["Address"] = "江苏连云港"; row["CarNo"] = "苏G88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 8; row["Name"] = "David Wu"; row["Age"] = 18; row["Address"] = "江苏淮安"; row["CarNo"] = "苏H88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 9; row["Name"] = "Dick Chen"; row["Age"] = 19; row["Address"] = "江苏盐城"; row["CarNo"] = "苏J88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 10; row["Name"] = "Sunny Yan"; row["Age"] = 26; row["Address"] = "江苏扬州"; row["CarNo"] = "苏K88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 11; row["Name"] = "Rainy Wang"; row["Age"] = 52; row["Address"] = "江苏镇江"; row["CarNo"] = "苏L88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 12; row["Name"] = "Scott Xu"; row["Age"] = 69; row["Address"] = "江苏泰州"; row["CarNo"] = "苏M88888"; dt.Rows.Add(row); row = dt.NewRow(); row["Id"] = 13; row["Name"] = "Richard Liu"; row["Age"] = 44; row["Address"] = "江苏宿迁"; row["CarNo"] = "苏N88888"; dt.Rows.Add(row); return dt; } } }
运行效果: