| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1493 人关注过本帖
标题:大佬们,帮忙指点一下,
只看楼主 加入收藏
肖臭臭
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2022-8-3
收藏
 问题点数:0 回复次数:9 
大佬们,帮忙指点一下,
大佬们,帮忙指点一下,如何遍历控件NumericUpDown的值    保存到ini,   或者写入序列化,读取反序列化
搜索更多相关主题的帖子: 写入 反序列化 序列化 读取 ini 
2022-08-03 15:22
龙胆草
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:6
帖 子:55
专家分:230
注 册:2022-6-17
收藏
得分:0 
不太明白,NumericUpDown的值只有一个,你可能是想要遍历它的数据范围吧?取最大值与最小值循环,不知是不是这个意思
2022-08-12 16:45
肖臭臭
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2022-8-3
收藏
得分:0 
回复 2楼 龙胆草
我现在用的保存Value的值到ini,有N个Value的值,就要敲 N行代码,numericUpDown1.Value  =  ;  想的是能不能用一行代码完成,保存整个窗体的值到XML 或者 ini 里面
2022-08-18 14:31
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1479
专家分:9035
注 册:2010-3-16
收藏
得分:0 
你这是打算遍历窗口中的所有NumericUpDown控件的值是吧。
程序代码:
        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);

        }
2022-08-18 14:38
肖臭臭
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2022-8-3
收藏
得分:0 
回复 4楼 apull
现在我是这样保存数据的,
            string S1 = E1_HmoeMode.Text;
            string S2 = E1_HomeHith.Text;
            string S3 = E1_HomeLow.Text;
            string S4 = E1_ValueAbs1.Text;
            string S5 = E1_ValueAbs2.Text;
            string S6 = E1_ValueAbs3.Text;
            string S7 = E1_ValueAbs4.Text;
            string S8 = E1_JogSpeed.Text;
            IniFunc.writeString("Information", "1", S1, filename);
            IniFunc.writeString("Information", "2", S2, filename);
            IniFunc.writeString("Information", "3", S3, filename);
            IniFunc.writeString("Information", "4", S4, filename);
            IniFunc.writeString("Information", "5", S5, filename);
            IniFunc.writeString("Information", "6", S6, filename);
            IniFunc.writeString("Information", "7", S7, filename);
            IniFunc.writeString("Information", "8", S8, filename);


这个是读取数据的
            string S1 = IniFunc.getString("Information", "1", null, filename);
            string S2 = IniFunc.getString("Information", "2", null, filename);
            string S3 = IniFunc.getString("Information", "3", null, filename);
            string S4 = IniFunc.getString("Information", "4", null, filename);
            string S5 = IniFunc.getString("Information", "5", null, filename);
            string S6 = IniFunc.getString("Information", "6", null, filename);
            string S7 = IniFunc.getString("Information", "7", null, filename);
            string S8 = IniFunc.getString("Information", "8", null, filename);
            E1_HmoeMode.Text  = S1;
            E1_HomeHith.Text  = S2;
            E1_HomeLow.Text   = S3;
            E1_ValueAbs1.Text = S4;
            E1_ValueAbs2.Text = S5;
            E1_ValueAbs3.Text = S6;
            E1_ValueAbs4.Text = S7;
            E1_JogSpeed.Text  = S8;

2022-08-18 16:06
肖臭臭
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2022-8-3
收藏
得分:0 
回复 4楼 apull
想实现一行代码保存数据,跟读取
2022-08-18 16:07
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1479
专家分:9035
注 册:2010-3-16
收藏
得分:0 
使用控件的tag保存ini文件的1-8。
使用下面函数需要提前给控件设置好tag属性。
比如
E1_HmoeMode.tag=1;
E1_HomeHith.tag=2;
...

程序代码:
        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);
                }
            }
        }

2022-08-18 17:39
肖臭臭
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2022-8-3
收藏
得分:0 
回复 7楼 apull
数据没写得进去,大佬
2022-08-19 08:17
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1479
专家分:9035
注 册:2010-3-16
收藏
得分:0 
NumericUpDown没有text属性,你的E1_HmoeMode.Text;,我猜控件应该是textbox,typeof(NumericUpDown)的判断压根就没通过。
不要照抄,根据自己情况修改下。
2022-08-19 08:38
魔法软糖
Rank: 2
等 级:论坛游民
帖 子:5
专家分:30
注 册:2022-8-20
收藏
得分:0 
把控件装进泛型集合,然后调用。
TextBox 需要修改成你的控件 Type 名。
程序代码:
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编辑过]

2022-08-21 21:24
快速回复:大佬们,帮忙指点一下,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018936 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved