如何在c#中设置windows窗体中的控件 [英] how can set controls in windows form in c#

查看:95
本文介绍了如何在c#中设置windows窗体中的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个包含许多复选框和控件的表单

第一次加载所有控件都将取消选中



然后如果我检查了一些控件,它就像表单设置控件一样使用

并在form_load部分中显示它将被检查< br $> b $ b



  public   class  MyController 
{
public void Thread_ContinuousChecker()
{
Form1 f = new Form1();
// 如果我使用new,则将我的控件功能重置为原始
f.Hide();
if (f.checkBox3.Checked)
{
Thread th = new 线程(f.files);
th.Start();
}
}
}
}

解决方案

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

使用设置在C#



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

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



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

  public   class  MyController 
{
< span class =code-keyword> 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).


这篇关于如何在c#中设置windows窗体中的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆