Enhanced GroupBox Control | CodeGuru

Enhanced GroupBox Control

Environment: VC6, Win98/NT4/2K If you want to customize the look of the standard GroupBox control then the SxGroupBox class can be most helpful for you. It provides functions for customizing the font, color, and style. Most of the work is done in the OnPaint message handler. You can easily change the OnPaint function yourself to […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 30, 2002
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: VC6, Win98/NT4/2K

If you want to customize the look of the standard GroupBox control then the
SxGroupBox class can be most helpful for you. It provides functions for customizing
the font, color, and style. Most of the work is done in the OnPaint message handler.
You can easily change the OnPaint function yourself to add other effects such as rounded
corners or other line styles or box styles.

You can follow these steps to use the class:

  1. Include the SxGroupBox.h header file in your dialog class header file.
  2. Use class wizard to create a control data member of type
    CSxGroupBox.  If the CSxGroupBox type does not appear in the class
    wizard control type combobox then just choose CButton and then manually edit your dialog
    class header file and replace the CButton with CSxGroupBox.  
  3. Add whatever commands you want to your dialog class cpp file to customize
    the appearance of the GroupBox.

A sample application is included that shows most of the features of SxGroupBox.

The following code snippet shows how to call some of the functions.

[In File YourDialogClass.h]

#include "SxGroupBox.h"
class YourDialogClass : public CDialog
{
  …
// Dialog Data
  //{{AFX_DATA(YourDialogClass)
  …
  CSxGroupBox	MyGroupBox;
  …
  //}}AFX_DATA
  …
}
[In File YourDialogClass.cpp]
void YourDialogClass::YourFunction()
{
  // create font
  CSxLogFont Arial12b(120,FW_BOLD,false,"Arial");
  // set the custom font, text color, and alignment
  MyGroupBox.SetFont( &Arial12b );
  MyGroupBox.SetTextColor( RGB(100,0,0) );
  MyGroupBox.SetTextAlign( BS_CENTER );
  // set the custom line colors, thickness, and style
  MyGroupBox.SetBoxColors( RGB(100,0,0), RGB(255,100,100) );
  MyGroupBox.SetLineThickness(2);
  MyGroupBox.SetLineStyle( BS_3D );
}

Downloads
Download demo project - 29 Kb
Download source - 5 Kb
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.