I am creating a C# .Net 4.8 Winform app with one MDI Form. This MDI Form has several panels and a split container.
When adding a childform I use the following code:
frm.Text = formTitleText;
frm.MdiParent = this;
frm.TopLevel = false;
frm.FormBorderStyle = FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
panelDeskTop.Controls.Add(frm);
panelDeskTop.Tag = frm;
frm.BringToFront();
lblTitleChildForm.Text = $"{frm.Text}({this.MdiChildren.Length})";
frm.Show();
The form shows in the panel, but is not added as a MDI Child. The Parent (This) is the MDI Parent and has property of IsMDIContainer. So the this.MdiChildren.Length is always 0.
Not sure why?
Thanks in advance.
CodePudding user response:
It's expected. You've set another parent for it: panelDeskTop.Controls.Add(frm);
.
Consider the following points: