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

    Exclamation Change Container Content

    I'm having some dificulties programing a GUI with windows forms inside Visual Studio.
    I wanted to know how can I change the content of a container... let's say I wave a split container on panel1 I have buttons and I want the GUI on panel to change accordingly to the buttons I press.

    For example I press button SEARCH on panel1 --> panel2 presents me searching fields.
    I press the button INFO --> panel2 a tab with options GLOBAL and DETAILED.
    and so on...

    Thank you gurus for your help!

  2. #2
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Change Container Content

    Create seperate User Controls for each of the things you want in Panel2. Then just make the 'active' one visible and hide the other(s) when the button is pressed in Panel1.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Change Container Content

    Quote Originally Posted by rliq View Post
    Create seperate User Controls for each of the things you want in Panel2.
    That's the key point. Futher, you can show/hide individual controls like sugested, or add/remove them to/from container Controls collection,
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  4. #4
    Join Date
    Dec 2009
    Posts
    48

    Talking Re: Change Container Content

    Thank you very much I also came up to this ideia some minutes after I aked but once again what's the code to load usercontrols into for example "splitContainer1.Panel1"?? some code please if anyone can help thanks

  5. #5
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Change Container Content

    Code is not necessarily required.

    Create a UserControl in the designer and rebuild your Project. Then your control should appear in your toolbox and you can drag it onto Panel2 like any other standard windows control. Use the Dock property to make it fill the Panel.

    You can even make your UserControl fire your/it's own events which you make up, like OnSwitchPanel() etc, which can be handled by it's container (like when you handle a Button's OnClick event). UserControls also help to keep your application modular and more easy to maintain, as all related code is within the UserControl and not sprawled across the your Main Form. If you create a general UserControl it can be used in many of your Projects.

    If you are just learning, don't be afraid to create a 'test' project' (or lots of them, they are easy to delete afterwards), no splitter, nothing complicated, just a form with a very simple UserControl you create. Play with it until you understand how they work. Once you understand, you will more quickly implement your real control in your real app. So you take a step back to move two steps forward. That's what I do and I suspect many others here do the same when looking at something new to them. Sorry if this last paragraph was patronising... Good Luck.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  6. #6
    Join Date
    Dec 2009
    Posts
    48

    Re: Change Container Content

    SOLVED! thanks

Tags for this Thread

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