Suppose you have a form called FormBase and all other forms inherit from this form.
For example, I have public class Form formTest : FormBase
What I have now in the ctor of formTest:
public class Form formTest : FormBase
{
public formTest()
{
InitializeComponent();
Program.MainForm.AddToFormSizes(this, this.Size);
}
}
This code adds the instance of formTest to a dictionary on the mainform with its size
This works, but I would like to move this code to FormBase so I don't have to put this line of code in every inherited form.
public class Form FormBase : Form
{
public FormBase()
{
InitializeComponent();
Program.MainForm.AddToFormSizes(this, this.Size);
}
}
Now, the problem is that when I do that, size will have the size of FormBase in design-time, not the size of formTest.
Is there a way in FormBase to capture the size of formTest or any other form that inherited from FormBase?
for reference, this is the code of AddToFormSizes in the MainForm
private Dictionary<Form, Size> _formSizes = new Dictionary<Form, Size>();
public void AddToFormSizes(Form form, Size size)
{
_formSizes.Add(form, form.Size);
}