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.
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 )
Parameters
- g
-
Type:
System.Drawing::Graphics^
The Graphics used to draw the check box.
- glyphLocation
-
Type:
System.Drawing::Point
The Point to draw the check box glyph at.
- textBounds
-
Type:
System.Drawing::Rectangle
The Rectangle to draw checkBoxText in.
- checkBoxText
-
Type:
System::String^
The String to draw with the check box.
- font
-
Type:
System.Drawing::Font^
The Font to apply to checkBoxText.
- flags
-
Type:
System.Windows.Forms::TextFormatFlags
A bitwise combination of the TextFormatFlags values.
- focused
-
Type:
System::Boolean
true to draw a focus rectangle; otherwise, false.
- state
-
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. 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(); } }
Available since 2.0