如何设置 GroupBox 标题颜色

发布于 2024-07-14 01:40:14 字数 204 浏览 5 评论 0原文

在我的系统上,组框的标题始终为深蓝色,如何更改?

你怎么样更改组框上边框的颜色? 显示了如何覆盖标题和边框的绘制,但我不想处理视觉样式和绘制圆角等。

On my system, the caption of a groupbox is always a dark blue colour, how do I change this?

The answer to How do you change the color of the border on a group box? shows how I can override the drawing of the caption and border, but I don't want to have to deal with Visual Styles and drawing rounded corners and the like.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

擦肩而过的背影 2024-07-21 01:40:15

以上对我没有帮助。
我在此处找到了解决方案 通过添加 GroupBox.Header 标签:

<GroupBox>
  <GroupBox.Header>
      <TextBlock Text="Header" Foreground="Black"/>
  </GroupBox.Header>
</GroupBox>

The above did not help me.
I found the solution here by adding the GroupBox.Header tag:

<GroupBox>
  <GroupBox.Header>
      <TextBlock Text="Header" Foreground="Black"/>
  </GroupBox.Header>
</GroupBox>
花开浅夏 2024-07-21 01:40:15

至少在Delphi中,标题只是字体颜色,你要确保parentfont是假的。 但这对你来说可能根本没有用,因为你标记了你的问题 .net

In Delphi at least, the caption is just the font color, you want to make sure parentfont is false. But that may not be useful at all to you since you tagged your question .net

草莓酥 2024-07-21 01:40:15

设置

groupBox1.ForeColor

会更改组框中其他控件(如按钮、标签等)的前景色,如果您只需要更改组框的文本颜色,则在大多数情况下这是不受欢迎的。 一个简单的解决方法是

    private void button1_Click(object sender, EventArgs e)
    {
        List<Color> lstColour = new List<Color>();
        foreach (Control c in groupBox1.Controls)
            lstColour.Add(c.ForeColor);

        groupBox1.ForeColor = Color.Red; //the colour you prefer for the text

        int index = 0;
        foreach (Control c in groupBox1.Controls)
        {
            c.ForeColor = lstColour[index];
            index++;
        }
    }

当然,如​​果您稍后以编程方式向组框添加控件,则上述代码可能毫无意义,但好处是您可以通过在代码中添加额外条件来处理所有这些情况。 为了双重确定,可以使用控件和前景色的键值对列表。

Setting

groupBox1.ForeColor

changes the forecolor of other controls like button, label etc residing inside the groupbox which has to be unwelcome in most cases if you only need to change the text colour of groupbox. A simple workaround will be

    private void button1_Click(object sender, EventArgs e)
    {
        List<Color> lstColour = new List<Color>();
        foreach (Control c in groupBox1.Controls)
            lstColour.Add(c.ForeColor);

        groupBox1.ForeColor = Color.Red; //the colour you prefer for the text

        int index = 0;
        foreach (Control c in groupBox1.Controls)
        {
            c.ForeColor = lstColour[index];
            index++;
        }
    }

Of course the above code can be meaningless if you are adding controls programmatically later to the groupbox, but the good thing is you can handle all that situations by adding extra conditions in code. To be doubly sure, a list of keyvaluepair of control and forecolor can be employed.

各自安好 2024-07-21 01:40:14

ForeColor 是控制组框中文本颜色的属性。

ForeColor is the property that controls the color of the text in a groupbox.

东北女汉子 2024-07-21 01:40:14

这应该可以解决问题:

public Form1()
{
  InitializeComponent();
  GroupBoxRenderer.RenderMatchingApplicationState = false;
  groupBox1.ForeColor = Color.Green;
}

This ought to do the trick:

public Form1()
{
  InitializeComponent();
  GroupBoxRenderer.RenderMatchingApplicationState = false;
  groupBox1.ForeColor = Color.Green;
}
辞慾 2024-07-21 01:40:14

看来我可以通过将 ForeColor 设置为我想要的颜色并将 FlatStyle 设置为 Standard 来设置标题颜色。

如果 FlatStyle 为 System,或者为 Standard,并且 ForeColor 未更改为默认值,则标题颜色将设置为 XP 主题中指定的颜色。

It seems I can set the caption colour by setting the ForeColor to the colour I want and setting the FlatStyle to Standard.

If the FlatStyle is System, or if it's Standard and the ForeColor isn't changed from the default, then the caption color is set to the color specified in the XP Theme.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文