您的位置:首页 > 其它

winform修改配置文件并保存,读取!

2013-01-10 09:16 225 查看
1、增加引用-->System.Configuration。

2、引用命名空间-->using System.Configuration。

3、代码:

//打开
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
//修改配置文件
config.AppSettings.Settings["test"].Value = textBox1.Text;
//保存
config.Save();
//读取
textBox2.Text = System.Configuration.ConfigurationSettings.AppSettings["test"].ToString();


4、重启应用程序以应用配置:

if (MessageBox.Show("Restart the program to apply the new configuration!", "Reminder", MessageBoxButtons.OK) == DialogResult.OK)
{
Application.Restart();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: