views:

2274

answers:

3

How do you change the text color of a group box in C#? The "documentation" doesn't even mention this, and Googling hasn't turned up an answer.

Thanks! Alan

+5  A: 

Use the ForeColor property. Sample code:

using System;
using System.Drawing;
using System.Windows.Forms;

class Test
{       
    [STAThread]
    static void Main(string[] args)
    {
        Form form = new Form();
        GroupBox group = new GroupBox();
        group.Text = "Text";
        group.ForeColor = Color.Red;
        form.Controls.Add(group);
        Application.Run(form);
    }
}
Jon Skeet
Works like a charm! Thanks Jon!
A: 

I'm assuming you are in winforms not in WPF now.

To change the text color of a group box you use ForeColor this changes the font colour in the header text.

Peter
+2  A: 

If you're referring to the groupbox text itself, then use what Jon Skeet posted. If you're referring to all the subsequent controls in the groupbox, then you can use this code:

        foreach (Control c in this.groupBox1.Controls)
        {
            c.ForeColor = this.groupBox1.ForeColor; //or whatever color you want
        }
BFree