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
peterkiersAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
peterkiersAuthor 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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
peterkiersAuthor Commented:
I have to put something here, i think:

        private void btnOK_Click(object sender, EventArgs e)
        {
            {
              xxx
            }
            this.Close();
        }
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
peterkiersAuthor 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 TomlinsonMiddle School Assistant TeacherCommented:
See my last post...you need to call Save() to update the values.  (line #4 in the first snippet)
0
 
peterkiersAuthor 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
 
peterkiersAuthor Commented:
I give you allready the points. Because I got to go.
Thank you for your help.

Peter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.