how can i find the checked state of radio buttons of one form from another form in c sharp .net 2010.
to use in situation like


IN FIRST FORM

if( otherform.radiobuttonname.checked=true)

{ ,,,,,do,,,}

)

Recommended Answers

All 3 Replies

I will show you how to do in both ways, becuase you didnt exactly specify in which direction you want to get a radio button check state.
So from from1 to check the radioButton on form2, and from form2 to check th radioButton on form1:

//FORM1
    public partial class Form1 : Form
    {
        Form2 f2;
        public Form1()
        {
            InitializeComponent();
        }

        public bool GetRadioButtonState_Form1()
        {
            return radioButton1.Checked ? true : false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            f2 = new Form2(this);
            f2.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //check for radio button on Form2:
            if (f2 != null)
            {
                bool bChecking = f2.GetRadioButtonState_Form2();
                MessageBox.Show("Radio button on Form1 is " + (bChecking ? "CHECKED!" : "NOT CHECKED!").ToString());
            }
            else
                MessageBox.Show("First open form2...");
        }
    }

//FORM2:
    public partial class Form2 : Form
    {
        Form1 f1;
        public Form2(Form1 _f1)
        {
            InitializeComponent();
            this.f1 = _f1;
        }

        public bool GetRadioButtonState_Form2()
        {
            return radioButton1.Checked ? true : false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Check for radio button on Form1:
            bool bChecking = f1.GetRadioButtonState_Form1();
            MessageBox.Show("Radio button on Form1 is " + (bChecking ? "CHECKED!" : "NOT CHECKED!").ToString());
        }
    }

really...thanks a lllotttt :)

You can mark the thread as answered, if you are satisfied with the asnwer, or add some at vote as helpful.
bye, bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.