Show Parent and Child off Main

G

Guest

I want to show the parent form (MDIContainer) and a child form on load of the
application. frmMain is the parent and frmDataEntry is the child.

static void Main()
{
Application.Run(new frmMain());

}

I tried adding the following code after the application run but received
errors.

frmDataEntry f = new frmDataEntry();
f.MdiParent = this;
f.Show();

How do I show both parent and child on start up of the application?
 
G

Guest

To create and add your child form, you would need to do so after the parent
form has been created and the best place to do that would be on the parent
form’s Load event.

Simply putting it inside of main would not work given that ‘this’ does not
actually exist (due to it being a static function), as well as that it would
not be executed until the Run() call has returned, something that would occur
only after the form has been closed.

Brendan
 
G

Guest

I added the following code in frmMain.

private void frmMain_Load(object sender, System.EventArgs e)
{
MessageBox.Show("test");
}


But nothing happens. I put a breakpoint on the frmMain_Load event and still
nothing happened, I don't think the form sees the event.
 
G

Guest

Elsewhere in the code of frmMain, probably within the function
InitializeComponent() check to make sure you have the line:

this.Load += new System.EventHandler(this.frmMain_Load);

If you don’t have it, you will of course need it (or something similar) to
make sure that frmMain_Load is called when the Load event fires... if you do
have that line and the handler is still not being called, that would be a
problem, and an odd one at that.

Brendan
 
N

Neo

have you added the event to form?? This code should be written in form
designer code... , i am not have correct syntax.. but you need to add
event functions to events.
frmMain.Load+=frmMain_Load
 
J

Jeffrey Tan[MSFT]

Hi Cadel,

Does the community's replies make sense to you? Is your problem resolved?
Please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top