0

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?

Tom1
  • 77
  • 1
  • 6

1 Answers1

0

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;
        }     
    }
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • that didn't do anything different for me ? – Tom1 Jan 08 '17 at 16:42
  • Works fine for me...but this will only affect forms that are **currently open and displayed** in your app. It doesn't change the "stored state" of the forms. If you open another form you'll have to apply the settings to your new instance(s). – Idle_Mind Jan 08 '17 at 17:01