如何使用c#.net将checkBox检查值从一个表单转换到另一个表单 [英] How to get checkBox checked value from one form onto another form using c#.net

查看:63
本文介绍了如何使用c#.net将checkBox检查值从一个表单转换到另一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有2个窗体,form1和form2 resp。表单2由复选框组成,我想在表单1上使用这些复选框选中的值,如何执行此操作?

Hi,
I am having 2 windows form form1 & form2 resp. Form 2 consist of checkboxes, I want to use these checkbox checked value on form 1 , how to do this?

推荐答案

你可以使用公共bool在form1 class ..

就像下面的例子





u can do it with a public bool inside the form1 class..
Just like the example below


namespace checkBox_test
{
    public partial class Form1 : Form
    {
        public bool chk = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            chk = checkBox1.Checked;
        }
    }
}







namespace checkBox_test
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form1 frm = new Form1();
            if (frm.chk)
                MessageBox.Show("checked");
            else
                MessageBox.Show("non");
        }
    }
}


这篇关于如何使用c#.net将checkBox检查值从一个表单转换到另一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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