| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1084 人关注过本帖
标题:求教:从XML文件读取控件的属性值
只看楼主 加入收藏
jqc304
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-7-3
收藏
 问题点数:0 回复次数:3 
求教:从XML文件读取控件的属性值
XML文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<SaveConfig>

  <BoxButtonInitial>
    <ComboBoxSelectIndex>0</ComboBoxSelectIndex>                        //comboBox的SelectedIndex值
    <textBox3>(local)</textBox3>                                        //textBox3的Text值
    <textBox4>ca</textBox4>                                              //textBox4的Text值
    <textBox5>ca</textBox5>                                              //textBox5的Text值
    <RadioButton1Checked>true</RadioButton1Checked>                      //RadioButton1的checked属性值
    <RadioButton2-9Enabled>false</RadioButton2-9Enabled>                 //RadioButton2-9的Enabled属性值
    <TextBox6-21Enable>false</TextBox6-21Enable>                          .....
    <Button6Enabled>false</Button6Enabled>                                ......
  </BoxButtonInitial>

</SaveConfig>


我想在一个Form的load事件里读取这些控件的设置,找了好的资料都弄不出来,特来请求高手解答,有没有其他好方法。谢谢!
我用的方法之一是:
            XmlDocument doc = new XmlDocument();
            doc.Load("XMLConf.xml");                                                                    //XMLConf.xml是上面的XML文件的文件名
            XmlNode node1 = doc.SelectSingleNode("SaveConfig/BoxButtonInitial/ComboBoxSelectIndex");
            comboBox1.SelectedIndex = Convert.ToUInt16(node1.Name);                                             //这里有错,怎么改呢?
            XmlNode node2 = doc.SelectSingleNode("SaveConfig/BoxButtonInitial/textBox3");
            textBox3.Text = node2.Name.ToString();
            XmlNode node3 = doc.SelectSingleNode("SaveConfig/BoxButtonInitial/textBox4");
            textBox4.Text = node3.Name.ToString();
            XmlNode node4 = doc.SelectSingleNode("SaveConfig/BoxButtonInitial/textBox5");
            textBox5.Text = node4.Name.ToString();
            XmlNode node5 = doc.SelectSingleNode("SaveConfig/BoxButtonInitial/RadioButton1Checked");
            radioButton1.Checked = Convert.ToBoolean(node5.Name);
            XmlNode node6 = doc.SelectSingleNode("SaveConfig/BoxButtonInitial/RadioButton2-9Enabled");
            radioButton2.Checked = Convert.ToBoolean(node6.Name);
            radioButton3.Checked = Convert.ToBoolean(node6.Name);
            radioButton4.Checked = Convert.ToBoolean(node6.Name);
            radioButton5.Checked = Convert.ToBoolean(node6.Name);
            radioButton6.Checked = Convert.ToBoolean(node6.Name);
            radioButton7.Checked = Convert.ToBoolean(node6.Name);
            radioButton8.Checked = Convert.ToBoolean(node6.Name);
            radioButton9.Checked = Convert.ToBoolean(node6.Name);
            XmlNode node7 = doc.SelectSingleNode("SaveConfig/BoxButtonInitial/TextBox6-21Enable");
            textBox6.Enabled = Convert.ToBoolean(node7.Name);
            textBox7.Enabled = Convert.ToBoolean(node7.Name);
            textBox8.Enabled = Convert.ToBoolean(node7.Name);
            textBox9.Enabled = Convert.ToBoolean(node7.Name);
            textBox10.Enabled = Convert.ToBoolean(node7.Name);
            textBox11.Enabled = Convert.ToBoolean(node7.Name);
            textBox12.Enabled = Convert.ToBoolean(node7.Name);
            textBox13.Enabled = Convert.ToBoolean(node7.Name);
            textBox15.Enabled = Convert.ToBoolean(node7.Name);
            textBox16.Enabled = Convert.ToBoolean(node7.Name);
            textBox17.Enabled = Convert.ToBoolean(node7.Name);
            textBox19.Enabled = Convert.ToBoolean(node7.Name);
            textBox20.Enabled = Convert.ToBoolean(node7.Name);
            textBox21.Enabled = Convert.ToBoolean(node7.Name);
            XmlNode node8 = doc.SelectSingleNode("SaveConfig/BoxButtonInitial/Button6Enabled");
            button6.Enabled = Convert.ToBoolean(node8.Name);

[[it] 本帖最后由 jqc304 于 2008-10-11 13:04 编辑 [/it]]
搜索更多相关主题的帖子: XML 控件 属性 文件 
2008-10-11 12:56
duanchangren
Rank: 1
等 级:新手上路
威 望:1
帖 子:252
专家分:0
注 册:2008-7-26
收藏
得分:0 
用序列化不好么
怎么这么用
2008-10-11 16:04
jqc304
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-7-3
收藏
得分:0 
兄台
能不能说清楚点啊,怎么用序列化?要不我把邮箱告诉你,麻烦你给个源代码看看,小弟我感激涕零啊......
2008-10-11 16:10
jqc304
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2008-7-3
收藏
得分:0 
解决了
已经自己想办法解决了。
2008-10-11 18:31
快速回复:求教:从XML文件读取控件的属性值
数据加载中...
 
   



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

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