C#如何创建每次加载表单时运行的过程?

时间:2017-01-31 13:51:30

标签: c# forms methods fullscreen windowed

在我的c#表单项目中,我希望每次加载任何表单时都会运行此方法。

        foreach (Form frm in Application.OpenForms)
        {
            frm.WindowState = FormWindowState.Normal;
            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.Bounds = Screen.PrimaryScreen.Bounds;
        }

1 个答案:

答案 0 :(得分:0)

我的主张: 创建一个BaseClass

public class BaseClass: Form

...并为其添加方法:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    foreach (Form frm in Application.OpenForms)
    {
        frm.WindowState = FormWindowState.Normal;
        frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        frm.Bounds = Screen.PrimaryScreen.Bounds;
    }
}

将这个确切的基类添加到每个表单中,例如:

public partial class Form1 : BaseClass