CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2009
    Posts
    8

    Question 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...

  2. #2
    Join Date
    Dec 2005
    Location
    algiers, Algeria
    Posts
    132

    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.
    Last edited by ledaker; February 11th, 2009 at 07:23 AM.

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: help need in Loading forms into split container

    Quote Originally Posted by ledaker View Post
    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.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  4. #4
    Join Date
    Feb 2009
    Posts
    8

    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.

  5. #5
    Join Date
    Oct 2004
    Posts
    206

    Re: help need in Loading forms into split container

    you could try

    Code:
    form2.TopLevel = false;
    this.splitContainer.Panel1.Controls.Add(form2);

  6. #6
    Join Date
    Feb 2009
    Posts
    8

    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.

  7. #7
    Join Date
    Oct 2004
    Posts
    206

    Re: help need in Loading forms into split container

    That's good, glad to help.

  8. #8
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: help need in Loading forms into split container

    Quote Originally Posted by bhanuprakash_kavi View Post
    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?
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured