<!-- Download Links -->
<!-- Article image -->
<!-- Main HTML starts here -->
This is a simple example of a control derived from a
class, to provide the (now fairly standard) 'boxless' separator, of which there
are countless MFC examples out there.
The only thing that you might not have come across before is the use of the
Firstly, it is used to paint disabled text for the control:
if( Enabled )
Brush br = new SolidBrush( ForeColor );
e.Graphics.DrawString( Text, Font, br, ClientRectangle, format );
ControlPaint.DrawStringDisabled( e.Graphics, Text, Font, BackColor,
ClientRectangle, format );
Then, it is used again to get the
control colors, relative to the current
Pen forePen = new Pen( ControlPaint.LightLight( BackColor ), SystemInformation.BorderSize.Height );
Pen forePenDark = new Pen( ControlPaint.Dark( BackColor ), SystemInformation.BorderSize.Height );
That's pretty much all there is to it.
Using the class
In your own code it is just a drop-in replacement for
If you're using the VS.NET IDE it isn't quite so simple (at least, not for me).
I can't find a way to persuade the ToolBox to recognize the control as
something it understands. If anyone has any ideas, then drop me a line.
However, it is easy enough to work around. Just drop a regular
down on your form. Then, switch to the code editor, and replace the 2 instances
HeaderGroupBox (not forgetting to
qualify the namespace appropriately). You can carry on using the Forms editor,
and it picks up our new rendering just fine.