title: C# hiding and showing a panel on top of a splitcontainer
body: <p>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".</p>
  
  <p>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.</p>
  
  <p>Code:
  Attempt 1:           </p>
  
  <pre><code>if (pnlPatients.Visible)
    pnlPatients.Hide();
  else
  {
    pnlPatients.Show();
    pnlPatients.BringToFront();
  }
  </code></pre>
  
  <p>Attempt 2:</p>
  
  <pre><code>pnlPatients.Visible = !pnlPatients.Visible;
  pnlPatients.Invalidate();
  </code></pre>
  
  <p>The strange thing is that both attempts work like this:</p>
  
  <p>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.</p>
  
  <p>Does anyone have an idea?</p>
  
  <p>Best regards</p>
  
  <p><strong>Edit: I also tried this but to no succes:</strong></p>
  
  <pre><code>pnlPatients.Visible = !pnlPatients.Visible;
  if (pnlPatients.Visible)
  {
    pnlPatients.BringToFront(); 
  }
  else
  {
    pnlPatients.SendToBack();
  }
  </code></pre>