RadioButtonRenderer.DrawRadioButton Method

Definition

Draws an option button control (also known as a radio button).

Overloads

DrawRadioButton(Graphics, Point, RadioButtonState)

Draws an option button control (also known as a radio button) in the specified state and location.

DrawRadioButton(Graphics, Point, Rectangle, String, Font, Boolean, RadioButtonState)

Draws an option button control (also known as a radio button) in the specified state and location, with the specified text, and with an optional focus rectangle.

DrawRadioButton(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Boolean, RadioButtonState)

Draws an option button control (also known as a radio button) in the specified state and location, with the specified text and text formatting, and with an optional focus rectangle.

DrawRadioButton(Graphics, Point, Rectangle, String, Font, Image, Rectangle, Boolean, RadioButtonState)

Draws an option button control (also known as a radio button) in the specified state and location, with the specified text and image, and with an optional focus rectangle.

DrawRadioButton(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, RadioButtonState)

Draws an option button control (also known as a radio button) in the specified state and location; with the specified text, text formatting, and image; and with an optional focus rectangle.

DrawRadioButton(Graphics, Point, RadioButtonState)

Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs

Draws an option button control (also known as a radio button) in the specified state and location.

C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Windows.Forms.VisualStyles.RadioButtonState state);

Parameters

g
Graphics

The Graphics used to draw the option button.

glyphLocation
Point

The Point to draw the option button glyph at.

state
RadioButtonState

One of the RadioButtonState values that specifies the visual state of the option button.

Remarks

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

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.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, 10

DrawRadioButton(Graphics, Point, Rectangle, String, Font, Boolean, RadioButtonState)

Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs

Draws an option button control (also known as a radio button) in the specified state and location, with the specified text, and with an optional focus rectangle.

C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string radioButtonText, System.Drawing.Font font, bool focused, System.Windows.Forms.VisualStyles.RadioButtonState state);
C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string? radioButtonText, System.Drawing.Font? font, bool focused, System.Windows.Forms.VisualStyles.RadioButtonState state);

Parameters

g
Graphics

The Graphics used to draw the option button.

glyphLocation
Point

The Point to draw the option button glyph at.

textBounds
Rectangle

The Rectangle to draw radioButtonText in.

radioButtonText
String

The String to draw with the option button.

font
Font

The Font to apply to radioButtonText.

focused
Boolean

true to draw a focus rectangle; otherwise, false.

state
RadioButtonState

One of the RadioButtonState values that specifies the visual state of the option button.

Examples

The following code example uses the DrawRadioButton(Graphics, Point, Rectangle, String, Font, Boolean, RadioButtonState) method in a custom control's OnPaint method to draw an option button in the state determined by the location of the mouse pointer. This code example is part of a larger example provided for the RadioButtonRenderer class.

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

    RadioButtonRenderer.DrawRadioButton(e.Graphics,
        ClientRectangle.Location, TextRectangle, this.Text,
        this.Font, clicked, state);
}

// Draw the radio button in the checked or unchecked state.
protected override void OnMouseDown(MouseEventArgs e)
{
    base.OnMouseDown(e);

    if (!clicked)
    {
        clicked = true;
        this.Text = "Clicked!";
        state = RadioButtonState.CheckedPressed;
        Invalidate();
    }
    else
    {
        clicked = false;
        this.Text = "Click here";
        state = RadioButtonState.UncheckedNormal;
        Invalidate();
    }
}

Remarks

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

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.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, 10

DrawRadioButton(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Boolean, RadioButtonState)

Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs

Draws an option button control (also known as a radio button) in the specified state and location, with the specified text and text formatting, and with an optional focus rectangle.

C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string radioButtonText, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags flags, bool focused, System.Windows.Forms.VisualStyles.RadioButtonState state);
C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string? radioButtonText, System.Drawing.Font? font, System.Windows.Forms.TextFormatFlags flags, bool focused, System.Windows.Forms.VisualStyles.RadioButtonState state);

Parameters

g
Graphics

The Graphics used to draw the option button.

glyphLocation
Point

The Point to draw the option button glyph at.

textBounds
Rectangle

The Rectangle to draw radioButtonText in.

radioButtonText
String

The String to draw with the option button.

font
Font

The Font to apply to radioButtonText.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

focused
Boolean

true to draw a focus rectangle; otherwise, false.

state
RadioButtonState

One of the RadioButtonState values that specifies the visual state of the option button.

Remarks

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

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.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, 10

DrawRadioButton(Graphics, Point, Rectangle, String, Font, Image, Rectangle, Boolean, RadioButtonState)

Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs

Draws an option button control (also known as a radio button) in the specified state and location, with the specified text and image, and with an optional focus rectangle.

C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string radioButtonText, System.Drawing.Font font, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.RadioButtonState state);
C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string? radioButtonText, System.Drawing.Font? font, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.RadioButtonState state);

Parameters

g
Graphics

The Graphics used to draw the option button.

glyphLocation
Point

The Point to draw the option button glyph at.

textBounds
Rectangle

The Rectangle to draw radioButtonText in.

radioButtonText
String

The String to draw with the option button.

font
Font

The Font to apply to radioButtonText.

image
Image

The Image to draw with the option button.

imageBounds
Rectangle

The Rectangle to draw image in.

focused
Boolean

true to draw a focus rectangle; otherwise, false.

state
RadioButtonState

One of the RadioButtonState values that specifies the visual state of the option button.

Remarks

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

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.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, 10

DrawRadioButton(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, RadioButtonState)

Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs
Source:
RadioButtonRenderer.cs

Draws an option button control (also known as a radio button) in the specified state and location; with the specified text, text formatting, and image; and with an optional focus rectangle.

C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string radioButtonText, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags flags, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.RadioButtonState state);
C#
public static void DrawRadioButton(System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string? radioButtonText, System.Drawing.Font? font, System.Windows.Forms.TextFormatFlags flags, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.RadioButtonState state);

Parameters

g
Graphics

The Graphics used to draw the option button.

glyphLocation
Point

The Point to draw the option button glyph at.

textBounds
Rectangle

The Rectangle to draw radioButtonText in.

radioButtonText
String

The String to draw with the option button.

font
Font

The Font to apply to radioButtonText.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

image
Image

The Image to draw with the option button.

imageBounds
Rectangle

The Rectangle to draw image in.

focused
Boolean

true to draw a focus rectangle; otherwise, false.

state
RadioButtonState

One of the RadioButtonState values that specifies the visual state of the option button.

Remarks

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

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.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, 10