View Code
1 //修改栏目订单的颜色
2 private void btnfunColor_Click(object sender, EventArgs e)
3 {
4 ColorDialog fontcolor = new ColorDialog();
5 if (fontcolor.ShowDialog() == DialogResult.OK)
6 {
7 strColors[Convert.ToInt32(cmbFunInfo.SelectedValue)] = fontcolor.Color;
8 int argb = fontcolor.Color.ToArgb();
9 Color.FromArgb(argb);
10 //写入文件
11 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
12 AppSettingsSection app = config.AppSettings;
13 app.Settings.Add(cmbFunInfo.SelectedValue.ToString(), argb.ToString());
14 config.Save(ConfigurationSaveMode.Modified);
15 }
16 }
然后读取指定的key值
View Code
1 /// <summary>
2 /// 读取指定key的值
3 /// </summary>
4 /// <param name="key"></param>
5 /// <returns></returns>
6 public static string GetValue(string key)
7 {
8 System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
9
10 if (config.AppSettings.Settings[key] == null)
11 return "";
12 else
13 return config.AppSettings.Settings[key].Value;
14 }
然后循环读取每个栏目所对应的数据
View Code
只是初步的实现了效果,还有一些东西是需要完善的,暂且放在这里,抽时间再完善一下,呵呵!
1 //设定颜色
2 private void SetDGVfontColors()
3 {
4 try
5 {
6 //循环遍历设定行的颜色
7 for (int i = 0; i < dgvOrders.Rows.Count; i++)
8 {
9 DataGridViewRow DGVRow = dgvOrders.Rows[i];
10 if (DGVRow != null)
11 {
12 switch (DGVRow.Cells["栏目名称"].Value as string)
13 {
14 case "中国移动":
15 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("1")); //字符串向颜色的转换
16 ;
17 break;
18 case "中国联通":
19 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("2"));
20 break;
21 case "中国电信":
22 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("3"));
23 break;
24 case "全国缴费":
25 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("4"));
26 break;
27 case "联通固话":
28 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("5"));
29 break;
30 case "电信固话":
31 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("6"));
32 break;
33 case "QQ币充值":
34 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("10"));
35 break;
36 case "全国游戏[直冲]":
37 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("11"));
38 break;
39 case "全国游戏[卡密]":
40 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("11"));
41 break;
42 case "中国电力":
43 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("12"));
44 break;
45 case "中国燃气":
46 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("13"));
47 break;
48 case "中国水费":
49 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("14"));
50 break;
51 case "业务办理":
52 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("18"));
53 break;
54 case "QQ币充值2":
55 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("19"));
56 break;
57 case "全国游戏2":
58 DGVRow.DefaultCellStyle.ForeColor = (Color)new ColorConverter().ConvertFrom(GetValue("20"));
59 break;
60 default:
61 DGVRow.DefaultCellStyle.ForeColor = Color.Black;
62 break;
63 }
64 }
65 }
66 }
67 catch
68 {
69 dgvOrders.ForeColor = Color.Black;
70 }
71 }