Advertise with us

Creating Event for Multiple Forms

I have tried a bunch of different things, so obviously I am now stuck... I have created a form, it has a button on it - that when clicked creates a new form. I can click away and create multiple forms this way. What I would like and cannot get to work is to have the main form have a second button on it - that when clicked will change all of the background colors on the secondary forms.

Last updated:1/30/2014 11:36:12 PM

1 Answers

Pravesh Singh
Pravesh Singh

Hi Samuel,

In your parent form do something like this.

private event Action<Color> ChangeColor;
private void CreateAndShowForm()
{
    var form2 = new Form2();
    ChangeColor +=form2.changeColor;
    /*do other stuff to show form*/
}
private void button1_Click(object sender, EventArgs e)
{
    ChangeColor(Color.Red);
}
In the child forms
public void changeColor(Color obj)
{
    /*change background color*/
}

Last updated:1/30/2014 11:36:12 PM

Answer