2017-01-08 22 views
0

我有一個選項菜單中的按鈕,我希望能夠一次更改每種表單的樣式。目前它只適用於選項菜單本身,因爲我使用了「this」。c#如何一次將WindowState,FormBorderStyle和Bounds更改應用於多個表單?

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; 
    } 

是否有某種方法可以使其適用於全球?

回答

0

遍歷Application.OpenForms()收集這樣的:

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; 
     }  
    } 
+0

是沒有做任何事情對我來說有什麼不同? – Tom1

+0

適合我......但這隻會影響當前在應用中打開並顯示**的表單。它不會更改表單的「存儲狀態」。如果打開另一個表單,則必須將設置應用於新實例。 –

相關問題