12

I'm developing a WinForms application and on one form, I use a GroupBox to group related controls together. I would like to style the caption in a particular way (e.g. making the caption bold). By altering the styling for the GroupBox, I can customise the caption, but it also alters the styling for controls within the GroupBox.

So far, there aren't that many child controls, so I'm individually resetting their styles back to the default, but I figure there has to be a better way... but I haven't figured it out so far.

Is there a way?

CJM
  • 11,908
  • 20
  • 77
  • 115

3 Answers3

8

The easiest way would be to put another panel inside the GroupBox, so that you only have to reset the font once.

There are plenty of other solutions, but they all require a lot more code. This keeps it nice and simple.

Scott Rippey
  • 15,614
  • 5
  • 70
  • 85
2

Control.Font (and other style-related properties) is implemented in such a way that it asks its parent for Font if it does not have explicitly set one. Obviously, this means that you would have to set it individually to all of the child controls to make sure they are not affected by changes in parent style.

Maybe you should take a look at owner-drawing the GroupBox caption?

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
olygofren
  • 41
  • 1
  • 5
1

I Solved this problem removing the default group caption and add a new label witch bold over the group at same place default group caption was.

Leo
  • 11
  • 2