保存程序配置到xml文件里
2012-03-31 08:53
309 查看
准备:
新建一个文本文档(.txt)修改扩展名为.xml,用记事本打开写入变量,格式如下:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Settings>
<text></text>
<R>255</R>
<G>255</G>
<B>255</B>
</Settings>
</NewDataSet>
定义:
DataSet ds; //来存放数据
string path; //XML文件路径
读取方法:
private void Form1_Activated(object sender, EventArgs e)
{
path = Application.StartupPath+"//Settings.xml";
ds = new DataSet();
ds.ReadXml(path); //ds以表格形式读取xml的数据
textBox1.Text = ds.Tables[0].Rows[0][0].ToString();
textBox1.BackColor =Color.FromArgb(Convert.ToInt16(ds.Tables[0].Rows[0][1])
,Convert.ToInt16(ds.Tables[0].Rows[0][2])
, Convert.ToInt16(ds.Tables[0].Rows[0][3]));
Activated -= new EventHandler(Form1_Activated);
}
保存方法:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ds.Tables[0].Rows[0][0] = textBox1.Text;
ds.Tables[0].Rows[0][1] = textBox1.BackColor.R;
ds.Tables[0].Rows[0][2] = textBox1.BackColor.G;
ds.Tables[0].Rows[0][3] = textBox1.BackColor.B;
ds.WriteXml(path);
}
注意:dataset可读入多个表,在
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Settings>
<text></text>
<R>255</R>
<G>255</G>
<B>255</B>
</Settings>
<Settings2>
<text></text>
<R>255</R>
<G>255</G>
<B>255</B>
</Settings2>
<Settings2>
<text></text>
<R>255</R>
<G>255</G>
<B>255</B>
</Settings2>
</NewDataSet>
中Settings与Settings1是dataset中的两个Table名,Settings1表有两行,text,R,G,B,为列名.
新建一个文本文档(.txt)修改扩展名为.xml,用记事本打开写入变量,格式如下:
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Settings>
<text></text>
<R>255</R>
<G>255</G>
<B>255</B>
</Settings>
</NewDataSet>
定义:
DataSet ds; //来存放数据
string path; //XML文件路径
读取方法:
private void Form1_Activated(object sender, EventArgs e)
{
path = Application.StartupPath+"//Settings.xml";
ds = new DataSet();
ds.ReadXml(path); //ds以表格形式读取xml的数据
textBox1.Text = ds.Tables[0].Rows[0][0].ToString();
textBox1.BackColor =Color.FromArgb(Convert.ToInt16(ds.Tables[0].Rows[0][1])
,Convert.ToInt16(ds.Tables[0].Rows[0][2])
, Convert.ToInt16(ds.Tables[0].Rows[0][3]));
Activated -= new EventHandler(Form1_Activated);
}
保存方法:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ds.Tables[0].Rows[0][0] = textBox1.Text;
ds.Tables[0].Rows[0][1] = textBox1.BackColor.R;
ds.Tables[0].Rows[0][2] = textBox1.BackColor.G;
ds.Tables[0].Rows[0][3] = textBox1.BackColor.B;
ds.WriteXml(path);
}
注意:dataset可读入多个表,在
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Settings>
<text></text>
<R>255</R>
<G>255</G>
<B>255</B>
</Settings>
<Settings2>
<text></text>
<R>255</R>
<G>255</G>
<B>255</B>
</Settings2>
<Settings2>
<text></text>
<R>255</R>
<G>255</G>
<B>255</B>
</Settings2>
</NewDataSet>
中Settings与Settings1是dataset中的两个Table名,Settings1表有两行,text,R,G,B,为列名.
相关文章推荐
- 在PDA程序中使用XML文件保存程序配置设置
- C# XML配置文件读写类(用于程序配置保存)
- c#通过xml保存程序配置文件
- Spring配置文件和SpringMVC配置文件 web.xml配置文件 保存自用
- xml基本操作和保存配置文件应用实例
- 用java程序读取xml文件中的配置信息
- apk反编译生成程序的源代码和图片、XML配置、语言资源等文件
- INI的替代品--XML配置文件读取与保存
- 一个将配置文件转换成xml的示例程序
- 读取程序集中的嵌入XML配置文件
- apk反编译生成程序的源代码和图片、XML配置、语言资源等文件
- 反编译apk生成程序的源代码和图片、XML配置、语言资源等文件
- xml基本操作和保存配置文件应用实例
- 保存NHibernate配置xml文件信息的源代码
- xxx.hbm.xml文件配置详解,适合保存
- 反编译apk生成程序的java源代码和图片、XML配置、语言资源等文件
- 保存类中变量或属性到XML配置文件
- Android之用XML文件对程序进行配置
- 保存类中变量或属性到XML配置文件
- Android拍照上传程序的xml配置文件