C# 如何制作一个每次加载表单时 运行 的过程?

C# how do I make a procedure that is run every time a form is loaded?

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

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

我的主张: 创建基类

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

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

public partial class Form1 : BaseClass