问题
I Create a Windows Forms application with C#.
I have a general Form and a panel on it.
I show subForm into this panel with code:
SubForm objForm= SubForm.InstanceForm();
this.IsMdiContainer = true;
objForm.TopLevel = false;
pnlSubSystem.Controls.Add(objForm);
objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
objForm.Dock = DockStyle.Fill;
objForm.Show();
now I want to show other form on subForm of this panel, But I dont know how to do it.
回答1:
I think your problem resolved by this code:
SubForm objForm= SubForm.InstanceForm();
objForm.TopLevel = false;
pnlSubSystem.Controls.Add(objForm);
objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
objForm.Dock = DockStyle.Fill;
objForm.Show();
回答2:
As I understand, you're very close. To add another form into subform
try the same code instead:
pnlSubSystem.Controls.Add(objForm);
use (where objForm2
is the new subForm
)
SubForm objForm2 = new SubForm();
objForm.Controls.Add(objForm2);
回答3:
Since you already got the answer that by removing this.IsMdiContainer = true;
your code would run perfectly fine. Because IsMdiContainer property changes the display and behavior of the form to an MDI parent form. When this property is set to true
, the form displays a submerged client area. All MDI child forms assigned to the parent form are displayed within its client area.
SubForm objForm= SubForm.InstanceForm();
objForm.TopLevel = false;
pnlSubSystem.Controls.Add(objForm);
objForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
objForm.Dock = DockStyle.Fill;
objForm.Show();
objForm form which will be the template for the child forms. Each time you want to create a new child window to your application, you can create a new instance of this template form and make the first form as its parent form.
//Create a new instance of the MDI child template form
SubForm objForm = new SubForm();
//Set parent form for the child window
objForm.MdiParent=this; // Last ObjForm or something
//Display the child window
objForm.Show();
回答4:
Another way:
objForm.TopLevel = false;
objForm.Parent = pnlSubSystem;
objForm.Show();
This is my first answer on Stackoverflow.
来源:https://stackoverflow.com/questions/17962341/how-to-load-form-inside-panel-other-form-in-win-app