samedi 5 août 2017

How do you save checkbox settings in with function in c#

I'm trying to create an application with a settings dialog. Inside the dialog, there will be a checkbox. I went to the settings panel in visual studio and made a name to the setting as "AutoEnable". I set the type to bool, and scope to user. I've also set the value to true. Meanwhile in the form, I've set a Checkbox1_CheckedChanged function to the checkbox and added the function as following:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if(checkBox1.Checked == true)
        {
            MainEditor m = new MainEditor();
            m.menustrip1.Visible = true;
        }
        if (checkBox1.Checked == false)
        {
            MainEditor m = new MainEditor();
            m.menustrip1.Visible = false;
        }
    }

When i tested it out, the checkbox was set to checked as the value I've set before. I unchecked the checkbox and close the dialog then open it up again. The result was fine...it was unchecked like i did. But the one problem i find is when i unchecked the checkbox and closed the dialog and when back to the MainEditor, the code function from checkbox1 was not working. What did i made wrong? Can anyone help? Thanks.




Aucun commentaire:

Enregistrer un commentaire