c# how to apply WindowState, FormBorderStyle and Bounds changes to multiple forms at once?

1k views Asked by At

I have buttons in an options menu that i want to be able to change the style of every form at once. At the moment it only applies to the options menu itself because I've used "this."

   private void Fullscreen_toggle_Click(object sender, EventArgs e)
    {
        this.WindowState = FormWindowState.Normal;
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.Bounds = Screen.PrimaryScreen.Bounds;
    }

    private void Windowed_toggle_Click(object sender, EventArgs e)
    {
        this.WindowState = FormWindowState.Maximized;
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
    }

Is there some way to make this apply globally?

1

There are 1 answers

2
Idle_Mind On BEST ANSWER

Iterate over the Application.OpenForms() collection like this:

    private void Fullscreen_toggle_Click(object sender, EventArgs e)
    {
        foreach (Form frm in Application.OpenForms)
        {
            frm.WindowState = FormWindowState.Normal;
            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.Bounds = Screen.PrimaryScreen.Bounds;
        }     
    }