Help needed with some code

Hi,

I have 2 forms, the main form is called MainForm and a dialog form is called frmSettings.

On the MainForm I have a schedulerControl, and on frmSettings a checkbox called chkShowMin.

What I want is when the user clicks on the checkbox chkShowMin, and presses the OK-button
the property ShowMinutes of the schedulerControl will be displayed, and offcaurse when the
user uncheck the checkbox the property ShowMinutes will be hidden. The setting of the checkbox
showmin will be loaded and saved to a inifile.

THAT ALL WORKS GREAT.

But what I want next is when the user starts my programm
That in the load-event will check if the property ShowMinutes
is set to true or false. If its true then show the minutes on the
schedulercontrol if not the hide the minutes.

I don't get that part right. Who can help me fix this?

Peter
FRMSETTINGS:

        private bool _ShowMin;

        private void btnOK_Click(object sender, EventArgs e)
        {
            {
                ShowMin = chkShowMin.Checked;
            }
            this.Close();
        }

        public bool ShowMin
        {
            get { return _ShowMin; }
            set { _ShowMin = value; }
        }

MAINFORM:

        private void MainForm_Load(object sender, EventArgs e)
        {
         if (frmSettings.ShowMin) { schedulerControl.DayView.TimeRulers[0].ShowMinutes = false; }  <==NOT GOOD
         else { schedulerControl.DayView.TimeRulers[0].ShowMinutes = true; }                              <==NOT GOOD

Open in new window

LVL 1
peterkiersAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The values being stored can be used by the forms...but they are not associated with any particular form.  They are associated with the application.

In the MSDN link I provided, take a close look at the section labeled "Using Settings at Run Time" as it has examples of how to read and write the settings.

For example, if you had created a bool setting called "ShowMinutes", you could read it with:
private void MainForm_Load(object sender, EventArgs e)
{
    schedulerControl.DayView.TimeRulers[0].ShowMinutes = Properties.Settings.Default.ShowMinutes;
}

Open in new window

0
 
käµfm³d 👽Commented:
Curious:

  You defined the property with the name "ShowMin" in FRMSETTINGS, but in MAINFORM you are trying to access "ShowMinutes". Is this just a copy/paste error or typo when creating the question?
0
 
ALaRivaCommented:
The problem is that you aren't loading the value that is saved in the INI file. What you need to be doing is in the load, you can check the value of the INI file, and use that to set it.

Then, you also need to do similar in the settings form. When it loads, you need to check the box (or not) depending on  the value saved in the INI and then set the settings form  checkbox appropriately.

hth

- Anthony
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
jdavistxCommented:
Also, is there any reason inparticular you're using an INI file?  It's my understanding that .NET doesn't provide any direct facilities for manipulating INI files; however, you could achieve a similar result with an XML file and I imagine with a lot less effort.  

You'd also be able to take advantage of things like Linq-to-XML:
http://msdn.microsoft.com/en-us/library/bb387061.aspx

Just something to consider.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
...and I would use a Setting to store that single boolean value:
http://msdn.microsoft.com/en-us/library/aa730869(VS.80).aspx
0
 
peterkiersAuthor Commented:
jdavistx, can you show me how?
0
 
peterkiersAuthor Commented:
I have to think, because I have no idea after getting all that response what to do.
I want to fix my problem with a lot less effort.
0
 
peterkiersAuthor Commented:
I have a question for Idle_Mind:

When i use a Setting do i have to do that on both forms?

P.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The setting is for the whole application...it can be read from anywhere.  So you'd read that value on form load so you know what the last state was and you'd read it when the settings form is opened so you know how to display it to the user.  You'd also read it after the settings form is closed (back in the main form) so you can update the state of the visual control.
0
 
peterkiersAuthor Commented:
IDLE MIND: You mean the Setting is for the mainform and all the other forms.
In other words all forms?

P.
0
 
peterkiersAuthor Commented:
Thank you everyone for the information.
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.