C# 隐藏和显示 splitcontainer 顶部的面板

发布于 2024-09-25 01:28:09 字数 875 浏览 4 评论 0原文

我有一个屏幕,它被几个分割容器分开。其中之一包含我制作的用户组件的矩形,这些“矩形”代表医院的病床。我想做的是让用户可以选择在“用户组件视图”和“数据网格视图”之间切换。

因此,我创建了一个面板 pnlPatients,它的大小与带有用户组件的 splitcontainer 的大小相同。当用户选择“更改视图”时,程序应该在两种布局之间切换。

代码: 尝试 1:

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

尝试 2:

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

奇怪的是,这两种尝试都是这样工作的:

用户首先看到“用户组件视图”。 如果他切换视图,它将正确地在前一个视图之上显示面板。 如果他再次切换,那么面板将被正确隐藏。 如果他再次切换视图,则面板将不会显示。请注意:调试时,面板的可见属性会正确更改为 TRUE 或 FALSE。但由于某种原因,只有第一次将其设置为可见 TRUE 时,面板才能被看到。

有人有想法吗?

最好的问候

编辑:我也尝试过,但没有成功:

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

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

Edit: I also tried this but to no succes:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

秉烛思 2024-10-02 01:28:09

如果有人不想浏览托尼的所有链接:

this.splitContainer.Panel2.Hide();
this.splitContainer.Panel2Collapsed = true;

In case someone doesn't want to wade through all of Tony's link:

this.splitContainer.Panel2.Hide();
this.splitContainer.Panel2Collapsed = true;
z祗昰~ 2024-10-02 01:28:09
    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;
        }
    }
    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;
        }
    }
她说她爱他 2024-10-02 01:28:09

不要使 Panel 控件失效,而是通过调用 this.Invalidate(true); 使 Host 窗体失效,以强制其重绘其所有子控件。

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);

笑脸一如从前 2024-10-02 01:28:09
 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;

        }

    }
 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;

        }

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文