EDIT -- simplified version to help focus
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()
{
try
{
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();
}
catch (Exception ex)
{
throw;
}
}
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?
Thanks!