Question about Settings-editor

Hi,

I have main form called MainForm and a dialogform called frmSettings.
on the frmSettings form i have a checkbox called chkShowMin

I have entered the values of the chkShowMin in the settings-editor:

chkShowMin - bool - User - True

But when I execute my programm the checkbox isn't checked and i have
set it to true in the editor.

What do I do wrong?

P.
LVL 1
Peter KiersOperatorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
In the Load() event for frmSettings you need to set the state of your CheckBox; there is no "link" between the setting the and the control:
private void frmSettings_Load(object sender, EventArgs e)
{
    chkShowMin.Checked = Properties.Settings.Default.chkShowMin;
}

Open in new window

0
Peter KiersOperatorAuthor Commented:
I have this:

        private void Settings_Load(object sender, EventArgs e)
        {
            this.chkShowMin.Checked = Properties.Settings.Default.ShowMin;

        }

        private void Settings_FormClosed(object sender, FormClosedEventArgs e)
        {
            Properties.Settings.Default.ShowMin = this.chkShowMin.Checked;

        }

But it isn't all is it. What do I have to do more...


Peter
0
Peter KiersOperatorAuthor Commented:
I have to put something here, i think:

        private void btnOK_Click(object sender, EventArgs e)
        {
            {
              xxx
            }
            this.Close();
        }
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
When closing, after setting the value, you need to Save them:
private void Settings_FormClosed(object sender, FormClosedEventArgs e)
        {
            Properties.Settings.Default.ShowMin = this.chkShowMin.Checked;
            Properties.Settings.Default.Save();
        }

Open in new window


Back in the main form, after the settings form closes, you'd need to update the ShowMinutes() property on your control.  If you displayed settings from with ShowDialog() then you could place this line directly after that to make it update:
// In main form, after the "settings" ShowDialog() line:
schedulerControl.DayView.TimeRulers[0].ShowMinutes = Properties.Settings.Default.ShowMin;

Open in new window

0
Peter KiersOperatorAuthor Commented:
I have this, but i doesn't work:

        private void Settings_Load(object sender, EventArgs e)
        {
            this.chkShowMin.Checked = Properties.Settings.Default.ShowMin;

        }

        private void Settings_FormClosed(object sender, FormClosedEventArgs e)
        {
            Properties.Settings.Default.ShowMin = this.chkShowMin.Checked;

        }

When I check my checkbox and close the frmSettings and then the application.
And then start my app again and open the frmSettings the chkShowMin is not checked???

What do I do wrong?

P.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
See my last post...you need to call Save() to update the values.  (line #4 in the first snippet)
0
Peter KiersOperatorAuthor Commented:
Oke, one little last Q.

When I click on the OK-button of the frmSettings-form.
and the chkshowmin was true then show the property
ShowMinutes (=true)
and if the chkshowmin was false then hidethe property
ShowMinutes (=false)

Could you help me with this before i give you the points.

P.
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Ok...so your Settings form code would look something like this:
public partial class Settings : Form
    {

        public Settings()
        {
            InitializeComponent();
        }

        private void Settings_Load(object sender, EventArgs e)
        {
            this.chkShowMin.Checked = Properties.Settings.Default.ShowMin;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.ShowMin = this.chkShowMin.Checked;
            Properties.Settings.Default.Save();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

    }

Open in new window


And back in your main form, you'd do something like:
private void btnSettings_Click(object sender, EventArgs e)
        {
            Settings frmSettings = new Settings();
            if (frmSettings.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // update your control
                schedulerControl.DayView.TimeRulers[0].ShowMinutes = Properties.Settings.Default.ShowMin;
            }
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Peter KiersOperatorAuthor Commented:
I give you allready the points. Because I got to go.
Thank you for your help.

Peter
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.