C#中的设置问题?

C#中的设置问题?,c#,winforms,settings,visual-c#-express-2010,C#,Winforms,Settings,Visual C# Express 2010,我的代码有点问题,它应该重做用户在设置中所做的更改。当我在关闭表单后单击“否”时,ribbonBar2会消失,但当我打开设置时,复选框仍然处于选中状态,尽管它不应该处于选中状态。为什么? Form1 frm1; public Form8(Form1 frm1): this() { this.frm1 = frm1; } private void checkBox1_CheckedChanged(object sender, EventArgs e) {

我的代码有点问题,它应该重做用户在设置中所做的更改。当我在关闭表单后单击“否”时,
ribbonBar2
会消失,但当我打开设置时,复选框仍然处于选中状态,尽管它不应该处于选中状态。为什么?

Form1 frm1;
public Form8(Form1 frm1): this()
{
    this.frm1 = frm1;
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{             
    frm1.ribbonBar2.Visible = checkBox1.Checked;            
}

private void form8_closing(object sender, FormClosingEventArgs e)
{
    Properties.Settings.Default.checkBox1 = checkBox1.Checked;

    DialogResult result1 = MessageBox.Show("Do you want to Save your Settings?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
    if (result1 == DialogResult.Yes)
    {
        Properties.Settings.Default.Save();
    }

    if (result1 == DialogResult.No)
    {
        checkBox1.Checked = !Properties.Settings.Default.checkBox1;
    }

    e.Cancel = false;  
}

看起来没人愿意帮你做这件事

您不会恢复保存的任何设置。如果我没弄错的话,你想这样做:

public Form8(Form1 frm1): this()
{
    // Restore the settings when loading the form
    checkBox1.Checked = Properties.Settings.Default.checkBox1;
}

private void form8_closing(object sender, FormClosingEventArgs e)
{
    if (DialogResult.Yes == MessageBox.Show("Do you want to Save your Settings?",
                    "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
    {
        // Set the setting and save it
        Properties.Settings.Default.checkBox1 = checkBox1.Checked;
        Properties.Settings.Default.Save();
    }
}

请不要写
==true
。除此之外<代码>复选框1.Checked=!Properties.Settings.Default.checkBox1不清楚您想要实现什么,也不清楚“当我打开设置时”的确切含义。请记住,如果用户单击“否”,您就不会保存设置,因此您不应该对更改没有进入设置文件感到惊讶。由于某些原因,复选框没有被取消选中,但功能区栏不可见,就像您尽了最大努力保存设置一样,可能是做得太多了。做得太好了。但是忘记了恢复它,将属性命名为“checkbox1”将没有帮助。在构造函数中添加一行。@HansPassant你能帮我解决这个问题吗?每个人都有不好的评论等等。我才16岁,正在学习C#