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?
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With