Exinta Enea
Exinta Enea

Reputation: 235

Change icon of all running forms

I have got 3 forms and on one of them there is a button which is supposed to change icons of all my running forms.

I cannot figure out how to change the icon on the other two forms, I have managed to do so on just one form (where the button is located).

I have tried this way:

private void button2_Click(object sender, EventArgs e)
    {
        this.Icon = Properties.Resources.Purple;
        Form1 f1 = new Form1();
        Form f2 = new Form2();
        f1.Icon = Properties.Resources.Purple;
        f2.Icon = Properties.Resources.Purple;
    }

... but had no success.

Basically, I am stuck here now, since the code above doesn't work for me:

private void button2_Click(object sender, EventArgs e)
    {
        this.Icon = Properties.Resources.Purple;
    }

Any ideas?

Upvotes: 1

Views: 164

Answers (1)

sa_ddam213
sa_ddam213

Reputation: 43626

You should be able to use the OpenForms collection in the Application class to iterate over all the open Forms and set the Icon

Example:

foreach (var form in Application.OpenForms.Cast<Form>())
{
    form.Icon = Properties.Resources.Purple; 
}  

Upvotes: 2

Related Questions