Should I load child forms in the constructor or FormLoad ()?
I have code that calls a custom class that inserts a form into a control. First, I declared my child forms outside the constructor, and then I called the FormPaint () procedure in FormLoad (), and then I loaded the forms as follows:
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);
Now they showed me a much better way to embed forms in container controls, since it belongs to my custom class here .
My question is where should I load them, since in the example they are loaded into the constructor, declaring them at the same time, for example:
public frmWWCModuleHost() { InitializeComponent(); WinFormCustomHandling.ShowFormInContainerControl(tpgCaseNotes, new XfrmTest()); }
This is obviously much less code. When loading in the constructor, will I use much more unnecessary resources? Will I get something? How can i decide?