如何设置标签的字体颜色一样的分组框的标题的颜色? [英] How do I set the Font color of a label to the same as the caption color of a GroupBox?
问题描述
我希望有相同的字体颜色作为我的组合框的标题的形式对一些标签,此外我想这些颜色改变,如果用户采用不同的主题对他们的系统。
I want to have some labels on a form with the same font color as the caption on my group boxes, and furthermore I want these colors to change if the user has applied a different Theme on their system.
我能做到这一点,而不从其默认更改分组框标题?
Can I do this without changing the GroupBox caption from its default?
更新:
我已经尝试设置标签前景色为ActiveCaption,这个看起来不错的默认(蓝)方案,但是当我的计划更改为橄榄绿色,标签和组框标题是不一样的。
I have tried setting the Label ForeColor to ActiveCaption, this looks okay for the Default (Blue) scheme, but when I change the scheme to Olive Green, the label and group box captions are not the same.
此外,组框正常行为是在设定的FlatStyle为标准设置字幕颜色前景色,但创建一个新的组框,并设置其前景色为ControlText,您必须首先将其设置为比ControlText其他东西,然后将其设置再来一遍。 (如果你不按照我的意思,然后尝试一下,看看。)
Also, the GroupBox normal behaviour is that setting the FlatStyle to Standard sets the caption colour to ForeColor, however to create a new GroupBox and set its ForeColor to ControlText, you must first set it to something other than ControlText and then set it back again. (If you don't follow what I mean, then try it and see.)
推荐答案
嗯,同样的问题?我会重复我的帖子:
Hmm, same question? I'll repeat my post:
using System.Windows.Forms.VisualStyles;
...
public Form1()
{
InitializeComponent();
if (Application.RenderWithVisualStyles)
{
VisualStyleRenderer rndr = new VisualStyleRenderer(VisualStyleElement.Button.GroupBox.Normal);
Color c = rndr.GetColor(ColorProperty.TextColor);
label1.ForeColor = c;
}
}
这篇关于如何设置标签的字体颜色一样的分组框的标题的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!