Should I load child forms in the Constructor or the FormLoad()?
I have some code that is calling a custom class that embeds a form in a control. I had originally been declaring my child forms outside the Constructor and then calling a FormPaint() routine in the FormLoad() to then load the forms like so:
internal frmWWCMCPHost frmWWCMCPHost = new frmWWCMCPHost();
internal frmWWCEnrollmentHost frmWWCEnrollmentHost = new frmWWCEnrollmentHost();
internal frmWWCMemberHost frmWWCMemberHost = new frmWWCMemberHost();
public frmWWCModuleHost()
{
InitializeComponent();
}
private void frmWWCModuleHost_Load(object sender, EventArgs e)
{
FormPaint();
}
public void FormPaint()
{
WinFormCustomHandling.ShowFormInControl(frmWWCMCPHost, ref tpgMCP, FormBorderStyle.FixedToolWindow,-4,-2);
WinFormCustomHandling.ShowFormInControl(frmWWCMemberHost, ref tpgMember, FormBorderStyle.FixedToolWindow, -4, -2);
WinFormCustomHandling.ShowFormInControl(frmWWCEnrollmentHost, ref tpgEnrollment, FormBorderStyle.FixedToolWindow, -4, -2);
// Call each top-Level (visible) tabpage's form FormPaint()
frmWWCMCPHost.FormPaint();
}
Now I have been shown a much better way of embedding forms in container controls, as it relates to my custom class, here.
My question is where should I be loading these as the example has them being loaded in the Constructor declaring them at the same time, like so:
public frmWWCModuleHost()
{
InitializeComponent();
WinFormCustomHandling.ShowFormInContainerControl(tpgCaseNotes, new XfrmTest());
}
Which is, obviously, much less code. By loading in the constructor will I be using far more unnecessary resources? Will I be gaining anything? How do I decide?
I prefer to use form's constructor. I mean setup everything before a form would be shown, not after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With