Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to embed a window form app within another. I can do a one level embed from say embedding form2 in form1. However I want to embed a third form say form3 within form2(which is itself is embedded within form1). When i click the form2 menu strip item it does nothing(perhaps because form3 is embedded within it ?).
How can I solve this please?

What I have tried:

C#
            var f2 = new Form2();//Within Form1
            f2.TopLevel = false;
            f2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            f2.Size = this.Size;
            f2.BringToFront();
            f2.Visible = true;
            this.Controls.Add(f2);

var f3 = new Form3();//Within form2
            f3.TopLevel = false;
            f3.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            f3.Size = this.Size;
            f3.BringToFront();
            f3.Visible = true;
            this.Controls.Add(f3);
Posted
Updated 3-Dec-16 2:28am

1 solution

The code you show doesn't embed Form3 inside Form2 - it embeds it in Form1 alongside Form2. If I simplify your code:
C#
var f2 = new Form2();
...
this.Controls.Add(f2);

var f3 = new Form3();
...
this.Controls.Add(f3);
What you would need to do is:
C#
var f2 = new Form2();
...
this.Controls.Add(f2);

var f3 = new Form3();
...
f2.Controls.Add(f3);
 
Share this answer
 
Comments
Nganku Junior 3-Dec-16 12:47pm    
I've tried to apply the fix you proposed but it doesn't get the job done. How can f2.controls.add (f3) be called in form1.? I was under form2 when the code
var f3= new Form3 ();
......
This. Controls.add (f3)
Was written. When I call the variables you advice be called from form 1 it superposes them controls on the same form

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