0

我的代码遇到了一些问题,该代码应该重做用户在设置中所做的更改。当我在关闭表单后单击“否”时,它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;  
}
4

1 回答 1

2

因为看起来没有人愿意帮助你...

您不会恢复您保存的任何设置。如果我理解你的话,你想做这样的事情:

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();
    }
}
于 2012-06-30T21:41:36.660 回答