Using VS 2005 C#
I have a main form that has a split container - I want to load a mdi child into one of the containers.
Can anyone provide a sample of the code required.
Thanks in advance.
Using VS 2005 C#
I have a main form that has a split container - I want to load a mdi child into one of the containers.
Can anyone provide a sample of the code required.
Thanks in advance.
Position a form in a Parent Container
dave kumar
Actually you have crossed types. The split container will provide two panels in which you can add your own controls. An MDIParent (which hosts MDIChildren) is a totally different animal.
For split container:
Create a new item in your project and select UserControl and name it myChild.cs and you will now see a blank container. Populate that container with what ever UI controls you want to display. Now when you build a project you will have your new control.
With the split container as your base control you now do this to put your control on the left side of the screen.
void Form1_Load(object sender, EventArgs args)
{
myChild child = new myChild();
child.splitContainer1.Panel2.Controls.Add(child);
child.Dock = DockingStyle.Fill;
}
For an MDI container:
Delete the split container and in the form properties find the MDIParent property and set it to true.
Add a new item in your project and make it a FORM not a user control and name it myChild.cs. Place the same controls in it and build your project to have your forms built and functional.
Now to add your MDIChild:
void Form1_Load(object sender, EventArgs args)
{
myChild child = new myChild();
child.MdiParent = this;
child.Show();
}
Notice the difference between the two in that you deal with controls on the splitcontainer and forms with MDIChildren. The MDIParent is a unique containing control and deals with forms. The showing of the child in a splitContainer is encompassed in the showing of the form itself and you dock the control so that it is sized and managed by the containing panel (assuming your controls are all properly anchored).
Hope this helps.
oananiev
Not through the designer, but you can do it programmatically. You need to do the following:
It will appear like a window locked within the panel. You can remove the border from the child form's designer and then maximize it by setting the WindowState, that is, if you don't want it to look like a window within the panel.
Mike Carlisle
Thanks - can you give me the specific code to add the child form to the container.