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 に答える