Multiple panels on a Winform

I'm attempting to add multiple panels onto a winform, some of which overlap.

I'm finding that the later panels that have been added refuse to appear even though the statement:

set Panelx::Visible to TRUE

is given

What am I doing wrong?

 

  • What may be happening is that your second panel has been created such that it is a child of the first panel instead of the form itself. That would make panel1 the container and if it was invisible then panel2 would also be invisible.

    If you are creating the two panels using the Winform Designer then make sure that the top left hand corner of panel2 does not lie within panel1 or it will generate the code-behind such that panel1 is the container for panel2.

    If you look in the .designer.cbl file for the form and see code like the following it means that panel1 is the container for panel2

         *>
         *> panel1
         *>
          invoke panel1::Controls::Add(panel2)
          ...

    You should instead see:

    *>
    *> Form1
    *>
        set self::ClientSize to new System.Drawing.Size( 384 362)
       
    invoke self::Controls::Add(panel1)
       
    invoke self::Controls::Add(panel2)

    Thanks.,

  • So to clarify...

    Having muliple panels on a WINFORM is fine just as long as the top left hand corner of each created panel does not lie within another panel??

    If thats the case what is the best way to approach the problem whereby on the left hand side of the form I have a listbox containing 30 entries. Depending on WHICH of the entries I choose a different set of input variables appear on the right hand side of the form.

    As you can appreciate I have to overlay a great number of panels in order to then allow this process to work as a single form but if theres another way.....??

  • So to clarify...

    Having muliple panels on a WINFORM is fine just as long as the top left hand corner of each created panel does not lie within another panel??

    If thats the case what is the best way to approach the problem whereby on the left hand side of the form I have a listbox containing 30 entries. Depending on WHICH of the entries I choose a different set of input variables appear on the right hand side of the form.

    As you can appreciate I have to overlay a great number of panels in order to then allow this process to work as a single form but if theres another way.....??

  • It may be better to look at using either a tabControl, where you set up a different TabPage for each set of input fields or create a User Control for each of the panels and add the required user control dynamically depending on the option selected.

    The later would probably be the easiest to maintain.

  • Verified Answer

    I am attaching an example of how to do this with user controls.

    This sample has a simple form with two radio buttons and a panel.

    Depending on which radio button is selected, the appropriate usercontrol will be added to the panel.

    Pressing the getData button at the bottom will get all the text fields from both user controls using properties and format a multiline textbox using the data.

    testuserpanel.zip