ini保存字体信息 保存颜色信息

 

ini文件格式

[WordFont]
FontName = "方正姚体"
FontSize = "14"
FontStyle = "Bold"

;R G B 
ForeColor = "10,18,255"

 

 

 

 

  IniFile ini = new IniFile(@"c:\1.INI");



const string Const_Wordfont = "WordFont";

const string Const_FontName = "FontName"; const string Const_FontStyle = "FontStyle"; const string Const_FontSize = "FontSize";
const string Const_ForeColor = "ForeColor"; const string Const_BackColor = "BackColor"; /*字体颜色*/ public Color FontWord_ForeColor { get { Color _color = Color.Black; try { string s = ini.ReadString(Const_Wordfont, Const_ForeColor, "1,2,3"); string[] arr = s.Split(','); if (arr.Length > 2) { int.TryParse(arr[0], out int r); int.TryParse(arr[1], out int g); int.TryParse(arr[2], out int b); _color = Color.FromArgb(r, g, b); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return _color; } set { string s = "" + value.R + "," + value.G + "," + value.B; ini.WriteString(Const_Wordfont, Const_ForeColor, s); } } /*字体背景颜色*/ public Color FontWord_BackColor { get { Color _color = Color.Black; try { string s = ini.ReadString(Const_Wordfont, Const_BackColor, "1,2,3"); string[] arr = s.Split(','); if (arr.Length > 2) { int.TryParse(arr[0], out int r); int.TryParse(arr[1], out int g); int.TryParse(arr[2], out int b); _color = Color.FromArgb(r, g, b); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return _color; } set { string s = "" + value.R + "," + value.G + "," + value.B; ini.WriteString(Const_Wordfont, Const_BackColor, s); } }

 

Ini类

https://files.cnblogs.com/files/xe2011/IniFiles.rar

 

posted @ 2021-10-10 18:54  XE2011  阅读(122)  评论(0编辑  收藏  举报