Search code examples
c#winformsuser-interfacecontrolsgroupbox

How do you change the color of the border on a group box?


In C#.NET I am trying to programmatically change the color of the border in a group box.

Update: This question was asked when I was working on a winforms system before we switched to .NET.


Solution

  • Building on the previous answer, a better solution that includes the label for the group box:

    groupBox1.Paint += PaintBorderlessGroupBox;
    
    private void PaintBorderlessGroupBox(object sender, PaintEventArgs p)
    {
      GroupBox box = (GroupBox)sender;
      p.Graphics.Clear(SystemColors.Control);
      p.Graphics.DrawString(box.Text, box.Font, Brushes.Black, 0, 0);
    }
    

    You might want to adjust the x/y for the text, but for my use this is just right.