I was wondering if you could help me with below?
I have a project with multiple windows forms. Most of these forms will be using same methods, therefore, I created BaseForm and inherited from it.
It was all working fine but when I added a few text boxes in designer to Form1 which inherits from BaseForm, Visual Studio started crashing. Now I can't open Form1 designer as VisualStudio crashes each time I do this.
Please see below my base class and Form1 which inherits from BaseForm. I done some research and found out that many people advise against using visual inheritance with windows forms.
Is there another way rather than inheritance or am I doing something wrong? Is it a problem that both baseform and Form1 use InitializeComponent()?
public partial class BaseForm : Form
{
private List<Form> OpenForms = new List<Form>();
public BaseForm()
{
ListOpenForms();
CloseOpenForms();
this.FormBorderStyle = FormBorderStyle.None;
InitializeComponent();
SetBackroundPicture();
ShowPostionForm();
}
private void ListOpenForms()
{
foreach (Form frm in Application.OpenForms)
{
OpenForms.Add(frm);
}
}
private void CloseOpenForms()
{
foreach (Form frm in OpenForms)
{
if (frm.Text != "MainMenu")
frm.Close();
}
}
private void ShowPostionForm()
{
this.MdiParent = MainMenu.MainForm;
this.Dock = DockStyle.Fill;
this.Show();
}
private void SetBackroundPicture()
{
this.BackgroundImage = global::OMSRoutine.Properties.Resources.BackgroundPlain;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
}
Form1:
public partial class Form1 : BaseForm
{
public Form2()
{
InitializeComponent();
}
}