Winform使用Settings保存數據

1.單擊“項目”,然後選擇“***屬性…”,然後選擇“設置”。

 

2.在“設置”中添加新設置

3.試試以下代碼:

private void Accept_Click(object sender, EventArgs e)
{
    Properties.Settings.Default.cb = checkBox1.Checked;
    Properties.Settings.Default.str = textBox1.Text;
    Properties.Settings.Default.Save();
}

private void LoadSetting_Click(object sender, EventArgs e)
{
    checkBox1.Checked = Properties.Settings.Default.cb;
    textBox1.Text = Properties.Settings.Default.str;
}

private void Cancel_Click(object sender, EventArgs e)
{
    Properties.Settings.Default.cb = false;
    Properties.Settings.Default.str = "";
    Properties.Settings.Default.Save();
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章