Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
Posted
Comments
[no name] 16-Aug-14 8:39am    
The easiest way would be to pass the checkbox instance to the form 2 constructor so you can use it there.

1 solution

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


C#
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;
        }
    }
}


C#
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");
        }
    }
}
 
Share this answer
 
Comments
[no name] 16-Aug-14 8:38am    
That would never work as you are creating a new instance of Form1 so the check box would have its default value all of the time.
M­­ar­­­­k 17-Aug-14 3:28am    
Oh.. try implementing a static method to retrieve the checkBox status !

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