大佬们,帮忙指点一下,
大佬们,帮忙指点一下,如何遍历控件NumericUpDown的值 保存到ini, 或者写入序列化,读取反序列化
private void button1_Click(object sender, System.EventArgs e) { string s = ""; foreach (var t in Controls) //遍历窗口所有控件,也可以用for (int i = 0; i < Controls.Count; i++)的方式 { if (t.GetType() == typeof(NumericUpDown)) //控件类型为NumericUpDown { NumericUpDown n = (NumericUpDown)t; s += n.Value.ToString() + " "; } } MessageBox.Show(s); }
void writeIni() { foreach (var t in Controls) { if (t.GetType() == typeof(NumericUpDown)) { NumericUpDown n = (NumericUpDown)t; IniFunc.writeString("Information", n.Tag.ToString(), n.Value.ToString(), filename); } } } void readIni() { foreach (var t in Controls) { if (t.GetType() == typeof(NumericUpDown)) { NumericUpDown n = (NumericUpDown)t; string S = IniFunc.getString("Information", n.Tag.ToString(), null, filename); n.Value = int.Parse(S); } } }
List<TextBox> 控件集合 = new List<TextBox>(); 控件集合.Add(E1_HmoeMode); 控件集合.Add(E1_HomeHith); //... //这里必须把控件都填进去,只需要运行一次。
// 写入 控件集合.ForEach(t => IniFunc.writeString("Information", "1", t.Text, filename);); // 读取 控件集合.ForEach(t => t.Text = IniFunc.getString("Information", "8", null, filename););
[此贴子已经被作者于2022-8-21 21:32编辑过]