tags:

views:

68

answers:

2

Hi there

I have a screen which is divided by a few splitcontainers. One of them contains rectangles which user components I made, these "rectangles" represent hospital beds. What I wanted to do is give users the option to toggle between this "user component view" and a "datagrid view".

So I created a panel pnlPatients which I give the same size as the splitcontainer with the user components. When the user selects "Change view" the program is supposed to toggle between the two layouts.

Code: Attempt 1:

if (pnlPatients.Visible)
  pnlPatients.Hide();
else
{
  pnlPatients.Show();
  pnlPatients.BringToFront();
}

Attempt 2:

pnlPatients.Visible = !pnlPatients.Visible;
pnlPatients.Invalidate();

The strange thing is that both attempts work like this:

The user first sees the "user component view". If he would toggle the view, it would correctly show the panel on top of the previous view. If he would toggle again then the panel would correctly be hidden. If he would then again toggle the view then the panel will not be shown. DO NOTE: while debugging, the visible property of the panel is correctly changed to TRUE or FALSE. But for some reason only the first time it is put to visible TRUE the panel can be seen.

Does anyone have an idea?

Best regards Clint Cambier

Edit: I also tried this but to no succes:

pnlPatients.Visible = !pnlPatients.Visible;
if (pnlPatients.Visible)
{
  pnlPatients.BringToFront(); 
}
else
{
  pnlPatients.SendToBack();
}
A: 

Instead of Invalidating the Panel control, invalidate the Host form to force it to redraw all of it's children as well by calling this.Invalidate(true);

jvanrhyn
I will try that in a second, I now tried adding an extra splitcontainer to see if I can somehow hide or show those. With the link Tony provided below. If that doesn't work I'll try this out, thanks.
Clint Cambier
A: 

Have a look at this

Tony
This seems to be doing the trick. By using the Panel1Collapsed and Panel2Collapsed booleans. Thanks!
Clint Cambier