GroupBox and/or Tab Control Font Colours

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From all the control properties I have seen, there isn't a way of changing
the font colour for GroupBox titles and TabPage titles. Is there any way
around this? Would it be possible to clone the control and modify it or are
the colours inherited from the OS colour schemes? I have no idea how to make
custom controls by the way. Any tips would be great. Thanks :o)
 
When using Visual Styles the forecolor is set by the current Theme.

It is possible to Inherit the controls and draw them as you wish. Groupbox
is relatively simple to modify, but TabControl is much more complex.

If you're not averse to using free third party controls, then you can
download TabControlEx from my site. The dll also includes
GroupBoxEx(supports Transparent Background) which I have just modified to
allow a custom forecolor with VisualStyles.
http://www.dotnetrix.co.uk/controls.html

If you want to attempt to create a custom TabControl then you will find
several tips on my site:
http://www.dotnetrix.co.uk/tabcontrols.html

....and some nice examples on codeproject:
http://www.codeproject.com/cs/miscctrl/flattabcontrol.asp
http://www.codeproject.com/dotnet/CustomTabControl.asp
 
Thanks for the reply Mick. I'm not fussed about the Tab Control font. The
GroupBox is essential however. I had a bit of a surf for info on either how
to modify the groupbox title font colour or overriding the inheritance. All I
found were other controls that other people had created. I'd rather not use
3rd party controls.

In order to change the font colour, am I able to do it through the Marshal
using unmanaged code (rather not go down that path) or will I have to clone
the control and make my own 3rd party control with an altered font colour? I
read a few things about intercepting the renderer using the drawing event for
controls and changing the colour of the "brush" the engine is using while it
draws the group box border and title text. Is that the most "thread" safe way
to do it? Links to documentation about most commonly used techniques would be
fantastic.

Thanks again Mick
 
There's a quick and simple way to get the desired effect:

Set the Groupbox.Text to ""
Place a label over the groupbox where the caption would have been.

You could also just Paint over the top of the existing caption in the
groupbox's Paint() method.

This all assumes that you are using VS2002\2003, as VS2005 allows Visual
Styles with FlatStyle.Standard. The reason VS2003 does not allow a custom
caption color is that the control must use FlatStyle.System in order to be
painted with Visual Styles and, therefore, uses System Colors for the
caption. I should have mentioned this earlier.
 
Yes I am using .Net 2005. I'll have a look into the Paint() method. I
suspected that the caption was inheriting System Colours. Thanks again :o)
 
Andrew McNab said:
Yes I am using .Net 2005. I'll have a look into the Paint() method. I
suspected that the caption was inheriting System Colours. Thanks again :o)

In .net 2005, you should just set FlatStyle.Standard. The Groupbox should
then paint the caption using whatever ForeColor you set.
 
I found the "problem". I was creating a TabControl just with the design
interface. I was messing around with properties to see what I could get the
control to look like before writing code that dynamically creates controls
during runtime. I set the fore colour of the TabPage to white. When I created
a group box within that tab page, it inherited the fore colour of the parent
but the caption text was still blue. I guess I was so tired when I was
messing around with it that I didn't try to change the fore colour of the
group box. Once you change it in the properties window, the text changes
colour. Seems the inheritance doesn't work. Thanks again :o)
 
Back
Top