help need in Loading forms into split container
Hi ,
I have a problem with loading forms into a split container.
I created a project which contains three forms.
Form1 , Form2, Form3.
Form1:
I loaded a split container into it.
A split container contains two panels (panel1, panel2).
I created a objects for Form2 , Form3 as (form2,form3)
I added those two forms into into split container..
this.splitContainer.Panel1.Controls.Add(form2);
this.splitContainer.Panel2.Controls.Add(form3);
When I Run the code, I got error saying
An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
Additional information: Top-level control cannot be added to a control.
I need a help to figure out this issue.
I advance thank you...
Re: help need in Loading forms into split container
I think that the best way to do that is to use a System.Windows.Forms.UserControl not a System.Windows.Forms.Form for Form2, Form3.
Re: help need in Loading forms into split container
Quote:
Originally Posted by
ledaker
I think that the best way to do that is to use a System.Windows.Forms.UserControl not a System.Windows.Forms.Form for Form2, Form3.
Yes as trying to load a form into a splitcontainer is just as if you want to put a cow into a bottle of milk instead doing the cows milk into the bottle. As you see it needs to get panels. Maybe you will find help in my articleseries abouit dockable forms. The links are on the bottom of my signature in this post. It explains all that sort of things you just seems me to need. :D
Re: help need in Loading forms into split container
I changed the from
System.Windows.Forms.Form to System.Windows.Forms.UserControl.
Now I am not able to handle onclose event.
I am not clear with your answer, can u make it some more clear, with some example.
Re: help need in Loading forms into split container
you could try
Code:
form2.TopLevel = false;
this.splitContainer.Panel1.Controls.Add(form2);
Re: help need in Loading forms into split container
its cools.
very easy solution.
Thanks a lot man, partially for a week I am trying to fix this issue.
Re: help need in Loading forms into split container
That's good, glad to help.
Re: help need in Loading forms into split container
Quote:
Originally Posted by
bhanuprakash_kavi
I changed the from
System.Windows.Forms.Form to System.Windows.Forms.UserControl.
Now I am not able to handle onclose event.
I am not clear with your answer, can u make it some more clear, with some example.
If you really want to use Forms you can do:
Code:
public Form1()
{
InitializeComponent();
Form2 formA = newForm2();
Form2 formB = newForm2();
formA.TopLevel = false;
formB.TopLevel = false;
splitContainer1.Panel1.Controls.Add(formA);
splitContainer1.Panel2.Controls.Add(formB);
formA.Show();
formB.Show();
}
But when closing one of the forms there is a lot to do like removing it from the container where you wanted to have your form. Resizing the form and all controls on its surface adequate to size changes of the split container. The split contaienr needs to catch whatever is done with the form, because closing the form means for the container to hide or shrink the panel where the form was placed. All that and lots of other things. The tutorial for all of this is in the signature of my post and it contains lots of pictures.
Whats the exact problem you have ? show a bit of your code and which error occurs in which line at which user action?