Home > DeveloperSection > Forums > Creating Event for Multiple Forms
Simons Hood
Simons Hood

Total Post:70

Points:494
Posted on    January-30-2014 11:16 PM

 C# C# 
Ratings:


 1 Reply(s)
 613  View(s)
Rate this:

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.



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-30-2014 11:36 PM

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*/

}


Don't want to miss updates? Please click the below button!

Follow MindStick