CheckBoxRenderer.DrawCheckBox Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Draws a check box control.
Overloads
DrawCheckBox(Graphics, Point, CheckBoxState) |
Draws a check box control in the specified state and location. |
DrawCheckBox(Graphics, Point, Rectangle, String, Font, Boolean, CheckBoxState) |
Draws a check box control in the specified state and location, with the specified text, and with an optional focus rectangle. |
DrawCheckBox(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. |
DrawCheckBox(Graphics, Point, Rectangle, String, Font, Image, Rectangle, Boolean, CheckBoxState) |
Draws a check box control in the specified state and location, with the specified text and image, and with an optional focus rectangle. |
DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, CheckBoxState) |
Draws a check box control in the specified state and location; with the specified text, text formatting, and image; and with an optional focus rectangle. |
DrawCheckBox(Graphics, Point, CheckBoxState)
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
Draws a check box control in the specified state and location.
public:
static void DrawCheckBox(System::Drawing::Graphics ^ g, System::Drawing::Point glyphLocation, System::Windows::Forms::VisualStyles::CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Windows.Forms.VisualStyles.CheckBoxState state);
static member DrawCheckBox : System.Drawing.Graphics * System.Drawing.Point * System.Windows.Forms.VisualStyles.CheckBoxState -> unit
Public Shared Sub DrawCheckBox (g As Graphics, glyphLocation As Point, state As CheckBoxState)
Parameters
- state
- CheckBoxState
One of the CheckBoxState values that specifies the visual state of the check 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 check box with the current visual style. Otherwise, it will draw the check box with the classic Windows style.
Applies to
DrawCheckBox(Graphics, Point, Rectangle, String, Font, Boolean, CheckBoxState)
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
Draws a check box control in the specified state and location, with the specified text, and with an optional focus rectangle.
public:
static void DrawCheckBox(System::Drawing::Graphics ^ g, System::Drawing::Point glyphLocation, System::Drawing::Rectangle textBounds, System::String ^ checkBoxText, System::Drawing::Font ^ font, bool focused, System::Windows::Forms::VisualStyles::CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string checkBoxText, System.Drawing.Font font, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string? checkBoxText, System.Drawing.Font? font, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state);
static member DrawCheckBox : System.Drawing.Graphics * System.Drawing.Point * System.Drawing.Rectangle * string * System.Drawing.Font * bool * System.Windows.Forms.VisualStyles.CheckBoxState -> unit
Public Shared Sub DrawCheckBox (g As Graphics, glyphLocation As Point, textBounds As Rectangle, checkBoxText As String, font As Font, focused As Boolean, state As CheckBoxState)
Parameters
- focused
- Boolean
true
to draw a focus rectangle; otherwise, false
.
- state
- CheckBoxState
One of the CheckBoxState values that specifies the visual state of the check 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 check box with the current visual style. Otherwise, it will draw the check box with the classic Windows style.
Applies to
DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Boolean, CheckBoxState)
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
Draws a check box control in the specified state and location, with the specified text and text formatting, and with an optional focus rectangle.
public:
static void DrawCheckBox(System::Drawing::Graphics ^ g, System::Drawing::Point glyphLocation, System::Drawing::Rectangle textBounds, System::String ^ checkBoxText, System::Drawing::Font ^ font, System::Windows::Forms::TextFormatFlags flags, bool focused, System::Windows::Forms::VisualStyles::CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string checkBoxText, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags flags, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string? checkBoxText, System.Drawing.Font? font, System.Windows.Forms.TextFormatFlags flags, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state);
static member DrawCheckBox : System.Drawing.Graphics * System.Drawing.Point * System.Drawing.Rectangle * string * System.Drawing.Font * System.Windows.Forms.TextFormatFlags * bool * System.Windows.Forms.VisualStyles.CheckBoxState -> unit
Public Shared Sub DrawCheckBox (g As Graphics, glyphLocation As Point, textBounds As Rectangle, checkBoxText As String, font As Font, flags As TextFormatFlags, focused As Boolean, state As CheckBoxState)
Parameters
- flags
- TextFormatFlags
A bitwise combination of the TextFormatFlags values.
- focused
- Boolean
true
to draw a focus rectangle; otherwise, false
.
- state
- CheckBoxState
One of the CheckBoxState values that specifies the visual state of the check box.
Examples
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.
virtual void OnPaint(PaintEventArgs ^e) override
{
Control::OnPaint(e);
CheckBoxRenderer::DrawCheckBox(e->Graphics,
ClientRectangle.Location, this->getTextRectangle(), this->Text,
this->Font, TextFormatFlags::HorizontalCenter,
clicked, state);
}
// Draw the check box in the checked or unchecked state, alternately.
virtual void OnMouseDown(MouseEventArgs ^e) override
{
Control::OnMouseDown(e);
if (!clicked)
{
clicked = true;
this->Text = "Clicked!";
state = CheckBoxState::CheckedPressed;
Invalidate();
}
else
{
clicked = false;
this->Text = "Click here";
state = CheckBoxState::UncheckedNormal;
Invalidate();
}
}
// Draw the check box in the current state.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
CheckBoxRenderer.DrawCheckBox(e.Graphics,
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)
{
base.OnMouseDown(e);
if (!clicked)
{
clicked = true;
this.Text = "Clicked!";
state = CheckBoxState.CheckedPressed;
Invalidate();
}
else
{
clicked = false;
this.Text = "Click here";
state = CheckBoxState.UncheckedNormal;
Invalidate();
}
}
' Draw the check box in the current state.
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
CheckBoxRenderer.DrawCheckBox(e.Graphics, _
Me.ClientRectangle.Location, TextRectangle, Me.Text, _
Me.Font, TextFormatFlags.HorizontalCenter, _
clicked, state)
End Sub
' Draw the check box in the checked or unchecked state, alternately.
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
MyBase.OnMouseDown(e)
If Not clicked Then
With Me
.clicked = True
.Text = "Clicked!"
.state = CheckBoxState.CheckedPressed
End With
Invalidate()
Else
With Me
.clicked = False
.Text = "Click here"
.state = CheckBoxState.UncheckedNormal
End With
Invalidate()
End If
End Sub
Remarks
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.
Applies to
DrawCheckBox(Graphics, Point, Rectangle, String, Font, Image, Rectangle, Boolean, CheckBoxState)
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
Draws a check box control in the specified state and location, with the specified text and image, and with an optional focus rectangle.
public:
static void DrawCheckBox(System::Drawing::Graphics ^ g, System::Drawing::Point glyphLocation, System::Drawing::Rectangle textBounds, System::String ^ checkBoxText, System::Drawing::Font ^ font, System::Drawing::Image ^ image, System::Drawing::Rectangle imageBounds, bool focused, System::Windows::Forms::VisualStyles::CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string checkBoxText, System.Drawing.Font font, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string? checkBoxText, System.Drawing.Font? font, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state);
static member DrawCheckBox : System.Drawing.Graphics * System.Drawing.Point * System.Drawing.Rectangle * string * System.Drawing.Font * System.Drawing.Image * System.Drawing.Rectangle * bool * System.Windows.Forms.VisualStyles.CheckBoxState -> unit
Public Shared Sub DrawCheckBox (g As Graphics, glyphLocation As Point, textBounds As Rectangle, checkBoxText As String, font As Font, image As Image, imageBounds As Rectangle, focused As Boolean, state As CheckBoxState)
Parameters
- focused
- Boolean
true
to draw a focus rectangle; otherwise, false
.
- state
- CheckBoxState
One of the CheckBoxState values that specifies the visual state of the check 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 check box with the current visual style. Otherwise, it will draw the check box with the classic Windows style.
Applies to
DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, CheckBoxState)
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
- Source:
- CheckBoxRenderer.cs
Draws a check box control in the specified state and location; with the specified text, text formatting, and image; and with an optional focus rectangle.
public:
static void DrawCheckBox(System::Drawing::Graphics ^ g, System::Drawing::Point glyphLocation, System::Drawing::Rectangle textBounds, System::String ^ checkBoxText, System::Drawing::Font ^ font, System::Windows::Forms::TextFormatFlags flags, System::Drawing::Image ^ image, System::Drawing::Rectangle imageBounds, bool focused, System::Windows::Forms::VisualStyles::CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string checkBoxText, System.Drawing.Font font, System.Windows.Forms.TextFormatFlags flags, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state);
public static void DrawCheckBox (System.Drawing.Graphics g, System.Drawing.Point glyphLocation, System.Drawing.Rectangle textBounds, string? checkBoxText, System.Drawing.Font? font, System.Windows.Forms.TextFormatFlags flags, System.Drawing.Image image, System.Drawing.Rectangle imageBounds, bool focused, System.Windows.Forms.VisualStyles.CheckBoxState state);
static member DrawCheckBox : System.Drawing.Graphics * System.Drawing.Point * System.Drawing.Rectangle * string * System.Drawing.Font * System.Windows.Forms.TextFormatFlags * System.Drawing.Image * System.Drawing.Rectangle * bool * System.Windows.Forms.VisualStyles.CheckBoxState -> unit
Public Shared Sub DrawCheckBox (g As Graphics, glyphLocation As Point, textBounds As Rectangle, checkBoxText As String, font As Font, flags As TextFormatFlags, image As Image, imageBounds As Rectangle, focused As Boolean, state As CheckBoxState)
Parameters
- flags
- TextFormatFlags
A bitwise combination of the TextFormatFlags values.
- focused
- Boolean
true
to draw a focus rectangle; otherwise, false
.
- state
- CheckBoxState
One of the CheckBoxState values that specifies the visual state of the check 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 check box with the current visual style. Otherwise, it will draw the check box with the classic Windows style.
Applies to
.NET