Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CheckBoxRenderer.DrawCheckBox Method (Graphics, Point, Rectangle, String, Font, TextFormatFlags, Boolean, CheckBoxState)

Draws a check box control in the specified state and location, with the specified text and text formatting, and with an optional focus rectangle.

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

public static void DrawCheckBox(
	Graphics g,
	Point glyphLocation,
	Rectangle textBounds,
	string checkBoxText,
	Font font,
	TextFormatFlags flags,
	bool focused,
	CheckBoxState state


Type: System.Drawing.Graphics

The Graphics used to draw the check box.

Type: System.Drawing.Point

The Point to draw the check box glyph at.

Type: System.Drawing.Rectangle

The Rectangle to draw checkBoxText in.

Type: System.String

The String to draw with the check box.

Type: System.Drawing.Font

The Font to apply to checkBoxText.

Type: System.Windows.Forms.TextFormatFlags

A bitwise combination of the TextFormatFlags values.

Type: System.Boolean

true to draw a focus rectangle; otherwise, false.

Type: System.Windows.Forms.VisualStyles.CheckBoxState

One of the CheckBoxState values that specifies the visual state of the check box.

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

The following code example uses the DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Boolean, CheckBoxState) method in a custom control's OnPaint method to draw a check box in the state determined by the location of the mouse pointer. This code example is part of a larger example provided for the CheckBoxRenderer class.

// Draw the check box in the current state. 
protected override void OnPaint(PaintEventArgs e)

        ClientRectangle.Location, TextRectangle, this.Text,
        this.Font, TextFormatFlags.HorizontalCenter,
        clicked, state);

// Draw the check box in the checked or unchecked state, alternately. 
protected override void OnMouseDown(MouseEventArgs e)

    if (!clicked)
        clicked = true;
        this.Text = "Clicked!";
        state = CheckBoxState.CheckedPressed;
        clicked = false;
        this.Text = "Click here";
        state = CheckBoxState.UncheckedNormal;

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft