Home All Groups Group Topic Archive Search About

GroupBox and/or Tab Control Font Colours

Author
10 Feb 2007 8:01 AM
Andrew McNab
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)

Author
10 Feb 2007 9:19 AM
Mick Doherty
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

Show quoteHide quote
"Andrew McNab" <AndrewMc***@discussions.microsoft.com> wrote in message
news:69A4D613-DFC7-41A6-AC82-17DD4827BB2A@microsoft.com...
> 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)
Are all your drivers up to date? click for free checkup

Author
11 Feb 2007 1:03 PM
Andrew McNab
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
Author
11 Feb 2007 8:09 PM
Mick Doherty
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.

Show quoteHide quote
"Andrew McNab" <AndrewMc***@discussions.microsoft.com> wrote in message
news:6896E130-8A5F-4964-8FDB-7523DD8F9507@microsoft.com...
> 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
Author
11 Feb 2007 10:23 PM
Andrew McNab
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)
Author
12 Feb 2007 10:55 AM
Mick Doherty
"Andrew McNab" <AndrewMc***@discussions.microsoft.com> wrote in message
news:332306FA-AC9A-4552-8F6F-34FD2842839F@microsoft.com...
> 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.

Author
13 Feb 2007 11:31 PM
Andrew McNab
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)
Author
14 Feb 2007 8:11 PM
Jeff Glatt
Could try XTabControl from http://www.springsys.com


-j


17DD4827B***@microsoft.com...
Show quoteHide quote
> 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)

Bookmark and Share