In my c# forms project I want this method to run every time I load any of my forms.
foreach (Form frm in Application.OpenForms)
{
frm.WindowState = FormWindowState.Normal;
frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
frm.Bounds = Screen.PrimaryScreen.Bounds;
}
My proposition: Create a BaseClass
public class BaseClass: Form
... and add method to it:
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;
}
}
Add this exact base class to each of your forms, like such:
public partial class Form1 : BaseClass