Working with controlls on different forms

Hello.

I have 2 forms. On form1 I have a button and on form2 I have a checkbox. When I press the button on form1 I want to check the checkbox on form2. Of course, assume that the checkbox form has already been shown. I am really stuck on this. Any ideas !



Answer this question

Working with controlls on different forms

  • taheath

    It's up to the relationship between the 1st form and the 2nd one.

    If the Form2 is model, you can use its Owner property. B4 moding Form2, u must set Form2.Owner. something like this:

    Form2 form2 = new Form2();

    Form2.Owner = this;

    Form2.ShowDialog();

    There are afew other ways, But the best one is it.



  • Brian Trautman

    i think it is answered on the C# General Forum



  • Jason T Primarily Care

    Create a public method on Form2 something like

    public void SetCheckBoxChecked(bool value)

    {

    checkBox1.Checked = value;

    }

    In your Form1's button click call this method on Form2's instance by passing true as an argument.


  • Working with controlls on different forms