简体   繁体   English

C#中的重叠面板

[英]Overlapping Panels in C#

I am using the GUI forms builder in c#. 我在c#中使用GUI表单生成器。 I have a TransparencyKey set, and the backGround color of the whole form is set to that Transparency key so the background of the form seems invisible. 我有一个TransparencyKey设置,并且整个表单的backGround颜色设置为该Transparency键,因此表单的背景看起来不可见。 I also have a login panel that appears at first and after the user logs in it disappears and the other panels become visible. 我还首先出现了一个登录面板,在用户登录后该面板消失,其他面板变为可见。 This all works except when I attempt to overlap any of the panels. 除了我尝试重叠任何面板时,所有这些都有效。 Send to back or bring to front make no difference. 退回或移到最前面也没关系。 If even one of the panels overlap a little both of those overlapping panels disappear? 如果甚至其中一个面板重叠,那么那些重叠面板都会消失吗? What could be wrong? 有什么事吗

Cheers Grant 干杯格兰特

Not sure if what I'll say will apply to what you're doing. 不知道我要说的内容是否适用于您的工作。 I was trying to do something similar today with panels in my windows form. 今天,我正在尝试使用Windows窗体中的面板执行类似的操作。 I had two panels that I wanted to toggle their visibility based on a databound control. 我有两个面板,我想根据一个数据绑定控件来切换它们的可见性。 PanelX would be visible while PanelY was invisible. 当PanelY不可见时,PanelX将可见。 Well I was getting a problem... PanelX would be visible and PanelY would be invisible. 好吧,我遇到了问题... PanelX将可见,而PanelY将不可见。 But if I changed the form inputs to where PanelY should be visible and PanelX should be invisible, they were both invisible. 但是,如果我将表单输入更改为PanelY应该可见,而PanelX应该不可见,则它们都是不可见的。 I could not get PanelY to be visible no matter what I did. 无论我做什么,我都无法看到PanelY。

Well the solution was this. 那么解决方案就是这样。 I had placed PanelY inside PanelX (not realizing that I did of course). 我已经将PanelY放置在PanelX内(当然没有意识到我确实这样做了)。 What I wanted was PanelX and PanelY to both be on the main form container. 我想要的是PanelX和PanelY都位于主窗体容器上。 But like I said, PanelY was inside PanelX's container... so when PanelX was invisible and PanelY should have been visible, PanelY was also invisible because it's container (PanelX) was invisible. 但是就像我说的那样,PanelY在PanelX的容器内...因此,当PanelX不可见并且应该显示PanelY时,PanelY也不可见,因为它的容器(PanelX)不可见。

So long story short, make sure your Panel's are in the proper container. 长话短说,请确保您的面板位于正确的容器中。

If this is WinForms, there is no concept at all of a Z-Order. 如果这是WinForms,则Z-Order根本没有概念。 Each panel will ask the parent form to paint it's background. 每个面板将要求父窗体绘制其背景。 For this reason, WinForms transparency seldom works as you would expect. 因此,WinForms透明性很少能像您期望的那样工作。

Having said that, I don't see why the panels would disappear entirely if there is any overlap. 话虽如此,我不明白为什么如果有任何重叠,面板将完全消失。 I have implemented this type of thing in the past and never seen that behavior. 我过去曾经实现过这种类型的事情,却从未见过这种行为。 Can you recreate this in a very small sample project and post the code? 您可以在一个非常小的示例项目中重新创建它并发布代码吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM