GroupBoxRenderer.DrawGroupBox Method

Definition

Draws a group box control.

Overloads

DrawGroupBox(Graphics, Rectangle, GroupBoxState)

Draws a group box control in the specified state and bounds.

DrawGroupBox(Graphics, Rectangle, String, Font, GroupBoxState)

Draws a group box control in the specified state and bounds, with the specified text and font.

DrawGroupBox(Graphics, Rectangle, String, Font, Color, GroupBoxState)

Draws a group box control in the specified state and bounds, with the specified text, font, and color.

DrawGroupBox(Graphics, Rectangle, String, Font, TextFormatFlags, GroupBoxState)

Draws a group box control in the specified state and bounds, with the specified text, font, and text formatting.

DrawGroupBox(Graphics, Rectangle, String, Font, Color, TextFormatFlags, GroupBoxState)

Draws a group box control in the specified state and bounds, with the specified text, font, color, and text formatting.

DrawGroupBox(Graphics, Rectangle, GroupBoxState)

Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs

Draws a group box control in the specified state and bounds.

C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.VisualStyles.GroupBoxState state);

Parameters

g
Graphics

The Graphics used to draw the group box.

bounds
Rectangle

The Rectangle that specifies the bounds of the group box.

state
GroupBoxState

One of the GroupBoxState values that specifies the visual state of the group box.

Examples

The following code example uses the DrawGroupBox(Graphics, Rectangle, GroupBoxState) method in a custom control's OnPaint method to draw a group box with a double border. This code example is part of a larger example provided for the GroupBoxRenderer class.

C#
// Draw the group box in the current state.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    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, state);
    }
}

Remarks

If visual styles are enabled in the operating system and visual styles are applied to the current application, this method will draw the group box with the current visual style. Otherwise, this method will draw the group box with the classic Windows style.

Applies to

.NET Framework 4.8.1 et autres versions
Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

DrawGroupBox(Graphics, Rectangle, String, Font, GroupBoxState)

Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs

Draws a group box control in the specified state and bounds, with the specified text and font.

C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string groupBoxText, System.Drawing.Font font, System.Windows.Forms.VisualStyles.GroupBoxState state);
C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? groupBoxText, System.Drawing.Font? font, System.Windows.Forms.VisualStyles.GroupBoxState state);

Parameters

g
Graphics

The Graphics used to draw the group box.

bounds
Rectangle

The Rectangle that specifies the bounds of the group box.

groupBoxText
String

The String to draw with the group box.

font
Font

The Font to apply to groupBoxText.

state
GroupBoxState

One of the GroupBoxState values that specifies the visual state of the group box.

Examples

The following code example uses the DrawGroupBox(Graphics, Rectangle, String, Font, GroupBoxState) method in a custom control's OnPaint method to draw a group box with a double border. This code example is part of a larger example provided for the GroupBoxRenderer class.

C#
// Draw the group box in the current state.
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    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, state);
    }
}

Remarks

If visual styles are enabled in the operating system and visual styles are applied to the current application, this method will draw the group box with the current visual style. Otherwise, this method will draw the group box with the classic Windows style.

Applies to

.NET Framework 4.8.1 et autres versions
Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

DrawGroupBox(Graphics, Rectangle, String, Font, Color, GroupBoxState)

Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs

Draws a group box control in the specified state and bounds, with the specified text, font, and color.

C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string groupBoxText, System.Drawing.Font font, System.Drawing.Color textColor, System.Windows.Forms.VisualStyles.GroupBoxState state);
C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? groupBoxText, System.Drawing.Font? font, System.Drawing.Color textColor, System.Windows.Forms.VisualStyles.GroupBoxState state);

Parameters

g
Graphics

The Graphics used to draw the group box.

bounds
Rectangle

The Rectangle that specifies the bounds of the group box.

groupBoxText
String

The String to draw with the group box.

font
Font

The Font to apply to groupBoxText.

textColor
Color

The Color to apply to groupBoxText.

state
GroupBoxState

One of the GroupBoxState values that specifies the visual state of the group box.

Remarks

If visual styles are enabled in the operating system and visual styles are applied to the current application, this method will draw the group box with the current visual style. Otherwise, this method will draw the group box with the classic Windows style.

Applies to

.NET Framework 4.8.1 et autres versions
Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

DrawGroupBox(Graphics, Rectangle, String, Font, TextFormatFlags, GroupBoxState)

Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs

Draws a group box control in the specified state and bounds, with the specified text, font, and text formatting.

C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string groupBoxText, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags flags, System.Windows.Forms.VisualStyles.GroupBoxState state);
C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? groupBoxText, System.Drawing.Font? font, System.Windows.Forms.TextFormatFlags flags, System.Windows.Forms.VisualStyles.GroupBoxState state);

Parameters

g
Graphics

The Graphics used to draw the group box.

bounds
Rectangle

The Rectangle that specifies the bounds of the group box.

groupBoxText
String

The String to draw with the group box.

font
Font

The Font to apply to groupBoxText.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

state
GroupBoxState

One of the GroupBoxState values that specifies the visual state of the group box.

Remarks

If visual styles are enabled in the operating system and visual styles are applied to the current application, this method will draw the group box with the current visual style. Otherwise, this method will draw the group box with the classic Windows style.

Applies to

.NET Framework 4.8.1 et autres versions
Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

DrawGroupBox(Graphics, Rectangle, String, Font, Color, TextFormatFlags, GroupBoxState)

Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs
Source:
GroupBoxRenderer.cs

Draws a group box control in the specified state and bounds, with the specified text, font, color, and text formatting.

C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string groupBoxText, System.Drawing.Font font, System.Drawing.Color textColor, System.Windows.Forms.TextFormatFlags flags, System.Windows.Forms.VisualStyles.GroupBoxState state);
C#
public static void DrawGroupBox (System.Drawing.Graphics g, System.Drawing.Rectangle bounds, string? groupBoxText, System.Drawing.Font? font, System.Drawing.Color textColor, System.Windows.Forms.TextFormatFlags flags, System.Windows.Forms.VisualStyles.GroupBoxState state);

Parameters

g
Graphics

The Graphics used to draw the group box.

bounds
Rectangle

The Rectangle that specifies the bounds of the group box.

groupBoxText
String

The String to draw with the group box.

font
Font

The Font to apply to groupBoxText.

textColor
Color

The Color to apply to groupBoxText.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

state
GroupBoxState

One of the GroupBoxState values that specifies the visual state of the group box.

Remarks

If visual styles are enabled in the operating system and visual styles are applied to the current application, this method will draw the group box with the current visual style. Otherwise, this method will draw the group box with the classic Windows style.

Applies to

.NET Framework 4.8.1 et autres versions
Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9