CREATING EVENT FOR MULTIPLE FORMS

Simons Hood

Total Post:70

Points:494
Posted by  Simons Hood
C# 
C#
 1007  View(s)
Ratings:
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.

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Creating Event for Multiple Forms

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

      Modified On Apr-04-2018 03:38:53 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!