且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在c#中设置windows窗体中的控件

更新时间:2023-12-06 08:52:34

您可以使用设置创建将存储所需首选项的值:

使用设置在C#



例如,您可以创建一个名为'CheckBox1','CheckBox2',CheckBox3'的bool设置值,然后在 Form1 您可以处理CheckBox控件的CheckedChanged事件,以便在更改时更改相应的设置值。这样的事情:

  private   void  checkBox3_CheckedChanged( object  sender,EventArgs e)
{
Properties.Settings.Default.CheckBox3 = this 跨度> .checkBox3.Checked;
}



然后在 MyController 中,您可以检查以下设置值:

  public   class  MyController 
{
public void Thread_ContinuousChecker()
{
if (Properties.Settings.Default.CheckBox3)
{
// ...
}
}
}



另外我不确定你指的是什么类型 f.files ,但请注意,您可以使用各种类型来设置值,其中一个是StringCollection 所以也许你可以使用它来存储你的文件(我假设文件路径)。


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


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();
               }
}
}
}

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:
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
    Properties.Settings.Default.CheckBox3 = this.checkBox3.Checked;
}


Then in MyController you can check these setting values:

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).