Search code examples
c#winformsvisual-studio-2012mdiparent

how to change properties of child form controls in parent form


I have a Mdiparent form containing a button and some child forms. How is it possible to change backcolor of all textboxes in all child forms when clicking the button in parent form?


Solution

  • This the ChilForm;

            public ChilForm()
            {
                InitializeComponent();
            }
    
            public void ChangeTextboxColor() 
            {
                textBox1.BackColor = Color.Yellow;
            }
    

    And this is Parent;

            ChilForm frm = new ChilForm();
    
            public Parent()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                //Shows the child
                frm.Show();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                //Changes color
                frm.ChangeTextboxColor();
            }