保存程序配置到config文件里

准备:
     在 项目/<项目名>属性/设置 选项卡里可以定义变量,范围中用户(User)指该变量可读写,程序(application)指只读,例如定义以下变量:
 
读取方法:

        private void Form1_Activated(object sender, EventArgs e)
        {
            textBox1.Text = Properties.Settings.Default.Text;
            textBox1.BackColor=Properties.Settings.Default.Backcolor;
        }

保存方法:
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Properties.Settings.Default.Text = textBox1.Text;
            Properties.Settings.Default.Backcolor = textBox1.BackColor;
            Properties.Settings.Default.Save();
        } 

注意: 在文件夹C:/Documents and Settings/Windows登录用户/Local Settings/Application Data/ 下 搜索:user.config  可找到该配置文件
posted @ 2012-03-31 08:46  影子科技  阅读(417)  评论(0编辑  收藏  举报