继承父母的背景色prevent按钮 [英] Prevent Button from inheriting BackColor of Parent
问题描述
当我有一个家长控制,有一个背景色
比 SystemColors.Control
等,但我有按钮在系统中他们得出我想要的家长控制。然而,当我不改变背景色的按钮
,它绘制在母的颜色。当我在背景色按钮
更改为 SystemColors.Control
,它不是在Windows主题绘制了。
左版本与 SystemColors.Control
键,右边则是在不改变背景色
。的
炸掉了,它看起来像这样。在这里,您可以看到按钮有一个坚实的背景。的
任何建议,我怎么能解决这个问题?
图片中的效果可以通过创建一个新的.NET 2.0的WinForms项目和不断变化的 Form1中
的构造函数如下完成的:
公共Form1中()
{
的InitializeComponent();
VAR的textBox =新文本框();
Controls.Add被(的textBox);
VAR按钮=新按钮的{text =L,宽度= 23,身高= 18,左= -1,顶= -1};
textBox.Controls.Add(按钮);
//禁止线下获取默认行为
button.BackColor = SystemColors.Control;
}
我unforuantely只能访问到Windows 7的时刻,所以我不能在XP等测试,但你叫应用程序。 EnableVisualStyles
在主
进入你的WinForms应用程序的呢?
在Windows 7的Aero启用按钮不承担父颜色,如果 Application.EnableVisualStyles
之称。
注:您应该设置 button.UseVisualStyleBackColor = TRUE;
并没有明确地设置背景色
按钮的属性。
When I have a parent control which has a BackColor
other than SystemColors.Control
, but I have buttons on that parent control that I want to be drawn in the system them. However, when I do not change the BackColor
of the buttons, it's drawn in the color of the parent. When I change the BackColor
of the button to SystemColors.Control
, it isn't drawn in the Windows theme anymore.
The left version is with SystemColors.Control
and the right is without changing the BackColor
.
Blown up, it looks like this. Here you can see that the buttons have a solid background.
Any suggestions how I can fix this?
The effect in the image can be accomplished by creating a new .NET 2.0 WinForms project and changing the constructor of Form1
to the following:
public Form1()
{
InitializeComponent();
var textBox = new TextBox();
Controls.Add(textBox);
var button = new Button { Text = "L", Width = 23, Height = 18, Left = -1, Top = -1 };
textBox.Controls.Add(button);
// Disable the line below to get the default behavior
button.BackColor = SystemColors.Control;
}
I unforuantely only have access to Windows 7 at the moment so I can't test on XP etc. but are you calling Application.EnableVisualStyles
in the Main
entry point of your WinForms application?
On Windows 7 with Aero enabled the buttons do not assume the parent color if Application.EnableVisualStyles
is called.
NB: You should set button.UseVisualStyleBackColor = true;
and do not explicitly set the BackColor
property of the button.
这篇关于继承父母的背景色prevent按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!