C# 隐藏和显示 splitcontainer 顶部的面板
我有一个屏幕,它被几个分割容器分开。其中之一包含我制作的用户组件的矩形,这些“矩形”代表医院的病床。我想做的是让用户可以选择在“用户组件视图”和“数据网格视图”之间切换。
因此,我创建了一个面板 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果有人不想浏览托尼的所有链接:
In case someone doesn't want to wade through all of Tony's link:
不要使 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);