GroupBoxRenderer Class

Note: This class is new in the .NET Framework version 2.0.

Provides methods used to render a group box control with or without visual styles. This class cannot be inherited.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public ref class GroupBoxRenderer sealed
public final class GroupBoxRenderer
public final class GroupBoxRenderer

The GroupBoxRenderer class provides a set of static methods that can be used to render a group box control. Rendering a control refers to drawing the user interface of a control. To draw a group box, use one of the DrawGroupBox methods. These methods provide a variety of text drawing options.

If visual styles are enabled in the operating system and visual styles are applied to the current application, DrawGroupBox will draw the group box with the current visual style. Otherwise, DrawGroupBox will draw the group box with the classic Windows style. This is useful if you are drawing a custom control that should automatically match the current visual style setting of the operating system.

This class wraps the functionality of a System.Windows.Forms.VisualStyles.VisualStyleRenderer that is set to one of the elements exposed by the System.Windows.Forms.VisualStyles.VisualStyleElement.Button.GroupBox class. For more information, see Rendering Controls with Visual Styles.

Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform Note: Visual styles are supported only on these platforms.

The following code example demonstrates how to create a custom control that uses the DrawGroupBox method to draw a group box with a double border if visual styles are enabled.

#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::VisualStyles;

namespace GroupBoxRendererSample
    public ref class CustomGroupBox : public Control
        Rectangle innerRectangle;
        GroupBoxState state;
        FlowLayoutPanel^ panel;

        CustomGroupBox() : Control()
            innerRectangle = Rectangle();
            state = GroupBoxState::Normal;
            panel = gcnew FlowLayoutPanel();

            this->Size = System::Drawing::Size(200, 200);
            this->Location = Point(10, 10);
            this->Text = "CustomGroupBox";
            this->Font = SystemFonts::IconTitleFont;

            innerRectangle.X = ClientRectangle.X + 5;
            innerRectangle.Y = ClientRectangle.Y + 15;
            innerRectangle.Width = ClientRectangle.Width - 10;
            innerRectangle.Height = ClientRectangle.Height - 20;

            panel->FlowDirection = FlowDirection::TopDown;
            panel->Location = Point(innerRectangle.X + 5,
                innerRectangle.Y + 5);
            panel->Size = System::Drawing::Size(innerRectangle.Width - 10,
                innerRectangle.Height - 10);

        // Draw the group box in the current state.
        virtual void OnPaint(PaintEventArgs^ e) override 

            GroupBoxRenderer::DrawGroupBox(e->Graphics, ClientRectangle,
                this->Text, this->Font, state);

            // Draw an additional inner border if visual styles are enabled.
            if (Application::RenderWithVisualStyles)
                GroupBoxRenderer::DrawGroupBox(e->Graphics, innerRectangle,

        // Pass added controls to the internal FlowLayoutPanel.
        virtual void OnControlAdded(ControlEventArgs^ e) override

            // Ensure that you do not add the panel itself.
            if (e->Control != this->panel)

    ref class Form1 : public Form
        Form1() : Form()
            CustomGroupBox^ groupBox1 = gcnew CustomGroupBox();
            groupBox1->Text = "Radio Button Display";

            // Add some radio buttons to test the CustomGroupBox.
            int count = 8;
            array<RadioButton^>^ buttonArray = 
                gcnew array<RadioButton^>(count);
            for (int i = 0; i < count; i++)
                buttonArray[i] = gcnew RadioButton();
                buttonArray[i]->Text = "Button " + (i + 1).ToString();

            if (Application::RenderWithVisualStyles)
                this->Text = "Visual Styles Enabled";
                this->Text = "Visual Styles Disabled";

int main()
    // If you do not call EnableVisualStyles below, then
    // GroupBoxRenderer automatically detects this and draws
    // the group box without visual styles.
    Application::Run(gcnew GroupBoxRendererSample::Form1());


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions