[英]C#: Background color problem
I am having trouble with background colors in C#. 我在C#中使用背景色遇到麻烦。 For some reason they are simply not working.
由于某些原因,它们根本无法工作。 Specifically on the System.Windows.Forms.Panel control.
特别是在System.Windows.Forms.Panel控件上。 Setting the BackColor property does nothing.
设置BackColor属性不会执行任何操作。 All I have is gray and all the efforts I have made will not change it.
我仅有的是灰色,我所做的一切努力都不会改变它。 Is there something that could be overriding this?
有什么可以超越这一点的吗? Am I approaching this the wrong way?
我是否以错误的方式处理此问题?
I had this problem with two overlayed panels in one form. 我在以一种形式放置两个覆盖面板时遇到了这个问题。 I inadvertently had one panel as a child of the other main when I created them in Design View.
在设计视图中创建面板时,我无意间将一个面板作为另一个主要面板的子面板。
If you want to have the Panel Control the same color as the Form's background color, then you can use this: 如果要使面板控件的颜色与窗体的背景颜色相同,则可以使用以下方法:
myPanel.Parent = this;
... I hope this helps :) ... 我希望这有帮助 :)
我有一些实例,其中控件必须同时指定了前景色和背景色,您可能还想尝试显式设置前景色,以查看是否可行。
It may be that your control is being repainted without your knowledge. 可能是您的控件在您不知情的情况下被重绘。
To try to rule this out, I would add a Form Load event, and force the following properties: 为了排除这种情况,我将添加一个Form Load事件,并强制执行以下属性:
private void Form1_Load(object sender, EventArgs e)
{
this.panel1.BackColor = System.Drawing.Color.Maroon; // or any other color
this.panel1.Visible = true
}
And on the designer, I would bring the control to the foreground. 在设计师身上,我会将控件置于前台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.