3

I want to embed a Form within another Form. Here is what I have tried:

private void Form1_Load(object sender, EventArgs e)
{
    Form2 form = new Form2();  
    form.TopLevel = false;  
    panel1.Controls.Add(form);  
    form.Dock = DockStyle.Fill;  
    form.Show();  
}

Form1 is the parent form. Form2 is the child form, which has a TextBox control.

The problem: After embedding the child form, the TextBox in the child form cannot be selected with the mouse.

Can anyone help?

DavidRR
  • 18,291
  • 25
  • 109
  • 191
bucherren
  • 299
  • 1
  • 3
  • 13

2 Answers2

1

I Googled the problem. From my research I concluded that it's not a good idea to embed a Form within a Panel. I took another approach and have now made the child Form as an MDI child.

Community
  • 1
  • 1
bucherren
  • 299
  • 1
  • 3
  • 13
  • Apparently another option is to set `FormBorderStyle = None` on `Form2`... which probably defeats the purpose since the behavior will be all wrong. http://stackoverflow.com/a/3075762/945456 – Jeff B Jul 23 '13 at 16:26
-1

You need to setup the parent of the Form before calling .Show()

form.Parent = this;

Phil Wright
  • 22,580
  • 14
  • 83
  • 137