I am having trouble with background colors in C#. For some reason they are simply not working. Specifically on the System.Windows.Forms.Panel control. Setting the BackColor property does nothing. 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?
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 :)
I have had instances where controls must have both the foreground and background colors specified, you might want to try setting the foreground color explicitly as well, to see if that works.
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:
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.
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.
精彩评论