【问题标题】:c# how to apply WindowState, FormBorderStyle and Bounds changes to multiple forms at once?c# 如何一次将 WindowState、FormBorderStyle 和 Bounds 更改应用到多个表单?
【发布时间】:2023-03-31 06:39:01
【问题描述】:

我在选项菜单中有按钮,我希望能够一次更改每个表单的样式。目前它只适用于选项菜单本身,因为我使用了“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;
    }

有没有办法让它在全球范围内应用?

【问题讨论】:

    标签: c# this bounds windowstate formborderstyle


    【解决方案1】:

    像这样遍历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;
            }     
        }
    

    【讨论】:

    • 这对我没有什么不同?
    • 对我来说很好......但这只会影响应用中当前打开并显示的表单。它不会改变表单的“存储状态”。如果您打开另一个表单,则必须将设置应用于您的新实例。
    猜你喜欢
    • 1970-01-01
    • 2012-07-12
    • 2022-06-15
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2018-07-29
    • 2020-12-09
    • 1970-01-01
    相关资源
    最近更新 更多