Panels

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

Hi All,

I have 2 panels that have controls on them in a win
form. On Init of app I hide panel2 and show panel1, no
problem. On button Click I hide panel 1 and show panel 2,
panel 1 disappears but no panel 2 with controls showing.

Any idea what I might be doing wrong ?

Thanks,

JJ
 
I'd almost bet the bank that your Panel2 got added to the wrong parent
They should be both added to whatever parent control is appropriate, such
as:

this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);

You can check this with panel2.Parent in code or simply check in the
InitializeComponent method and inspect the Add methods to see where panel2
is being added. If it's being added to
this.panel1.Controls.Add(panel2);
then you'll never see it.

Chris R.
 
I concur with Chris's analysis. Moreover, once you have fixed the problem,
be careful when using the form designer. It is really easy to resurect the
problem again and again. Trust me. :(

--Ken
 
Hi All, Chris,

I found this in the initialize component:
this.panel1.Controls.Add(this.panel2);
and have commented it out. It Works!
Also I noticed that the form designer put this in for the
panels:

this.panel1.SuspendLayout();
this.panel2.SuspendLayout();

What does this do?

P.S. By the way I had commented them out and put in your
code to get it to work right.

Thanks,
JJ
 
Back
Top