Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a form with the many check boxes and controls
first time it will be load all controls will unchecked

then if i am checked some controls,it use as like as form setting controls
and show in form_load section that it will be checked


C#
public class MyController
       {
           public void Thread_ContinuousChecker()
           {
               Form1 f = new Form1();
//if i am goes with new then it reset my controls functionality as original
               f.Hide();
               if (f.checkBox3.Checked)
               {
                   Thread th = new Thread(f.files);
                   th.Start();
               }
}
}
}
Posted
Updated 17-Mar-15 1:09am
v4
Comments
Andy Lanng 17-Mar-15 6:27am    
What are you asking? Are you asking how to save the settings locally / on a server, or are you asking how to check / uncheck checkboxes programmatically?
Aditya Chauhan 17-Mar-15 6:35am    
not programtically ..?
how can store the form controls functionality is it checked or not when i call it in another class without making form f = new Form1();
Sinisa Hajnal 17-Mar-15 7:21am    
Your question is not clear. If you need to create strictly one form, consider Singleton pattern. If you need persistence, decide if you want to save things into database, XML file, app config or any other possible method of saving your state and go with it.

1 solution

You can use Settings to create values that will store required preferences:
Using Settings in C#

For example you could create a bool setting values of name 'CheckBox1', 'CheckBox2', CheckBox3' and then in Form1 you can handle the CheckedChanged event of your CheckBox controls so that on their change you change the appropriate setting value. Something like this:
C#
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
    Properties.Settings.Default.CheckBox3 = this.checkBox3.Checked;
}

Then in MyController you can check these setting values:
C#
public class MyController
{
    public void Thread_ContinuousChecker()
    {
        if (Properties.Settings.Default.CheckBox3)
        {
            // ...
        }
    }
}

Also I'm not sure on what type are you referring with f.files, but note that there are various types that you can use for setting values, one of which is StringCollection so maybe you can use that to store your files (I presume file paths).
 
Share this answer
 
Comments
Aditya Chauhan 17-Mar-15 7:34am    
create a bool setting values of name 'CheckBox1', 'CheckBox2', CheckBox3

i have created but not accessible

Properties.Settings.Default.CheckBox3

any suggestion how
Mario Z 17-Mar-15 7:45am    
Have you created the setting value like shown in that "Using Settings in C#" article?
See this image:
https://i-msdn.sec.s-msft.com/dynimg/IC51604.gif
This is where you want to define those values. Does that help?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900