Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display two child forms on a button click in a parentform in C#.net.

I have to display two child forms on a button click.These child forms objects are created in the parentform load and two panels are given in the parent form,rhese childform objects are added to the panel attributes.But only one child form is displaying.
In the parentform load,the below code is given:

C#
TextToSpeak Sform = new TextToSpeak();
Sform.TopLevel = false;
Sform.Dock = DockStyle.Fill;
Sform.TopMost = false;
panel1.Controls.Add(Sform);
Sform.Parent = this;
Sform.ShowIcon = true;
Sform.FormBorderStyle = FormBorderStyle.Fixed3D;
Sform.BringToFront();
Sform.Show();

ChatBot Cform = new ChatBot();
Cform.Dock = DockStyle.Fill;
Cform.TopMost = false;
Cform.TopLevel = false;
panel2.Controls.Add(Cform);

Cform.Parent = this;
Cform.ShowIcon = true;
Cform.FormBorderStyle = FormBorderStyle.Fixed3D;
Cform.BringToFront();
Cform.Show();
Posted
Updated 31-Aug-11 20:02pm
v2
Comments
Prerak Patel 1-Sep-11 2:02am    
Use code block for code segment.

Hello,

Personally I would use usercontrols rather than forms to do that.

UserControl1 userControl1 = new UserControl1();
UserControl2 userControl2 = new UserControl2();
this.panel1.Controls.Add(userControl1);
this.panel2.Controls.Add(userControl2);
userControl1.Dock = DockStyle.Fill;
userControl2.Dock = DockStyle.Fill;



Valery.
 
Share this answer
 
You've set the Dock to Fill. Which means that one form will be on top of the other. That's why you can't see both.

I assume you're trying to create an MDI application. Set the start location correctly, and don't set the Dock to Fill.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900