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

来源:互联网 发布:切腹女视频真假 知乎 编辑:程序博客网 时间:2024/05/17 01:56

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();                }


原创粉丝点击