C # hides and shows a panel on top of a separation container

I have a screen that is divided by several separation containers. One of them contains rectangles that I created custom components, these "rectangles" are hospital beds. I would like to give users the ability to switch between this “custom component view” and the “datagrid” view.

So, I created the pnlPatients panel, which I give to the size of the shared container with custom components. When the user selects "Change View", the program should switch 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();

It is strange that both attempts work like this:

" ". , . , . , . : TRUE FALSE. - , TRUE, .

- ?

: , :

pnlPatients.Visible = !pnlPatients.Visible;
if (pnlPatients.Visible)
{
  pnlPatients.BringToFront(); 
}
else
{
  pnlPatients.SendToBack();
}
+3
5
+2

- :

this.splitContainer.Panel2.Hide();
this.splitContainer.Panel2Collapsed = true;
+5
    int control =  0;

    private void hideShowLogToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (control == 0)
        {
            control = 1;

            splitContainer1.Panel2Collapsed = false;

            splitContainer1.Panel1Collapsed = true;

        }
        else if (control == 1)
        {
            control = 0;

            splitContainer1.Panel2Collapsed = true;

            splitContainer1.Panel1Collapsed = false;
        }
    }
+3

, Panel, , , this.Invalidate(true);

0
 bool state;
    private void btn_Click(object sender, EventArgs e)
    {
        if (state)
        {
            splitContainer1.Panel1Collapsed = true;
            splitContainer1.Panel2Collapsed = false;
            state = false;

        }
        else
        {
            splitContainer1.Panel1Collapsed = false;
            splitContainer1.Panel2Collapsed = true;
            state = true;

        }

    }
0
source

Source: https://habr.com/ru/post/1767124/


All Articles