CheckBoxRenderer Class
Provides methods used to render a check box control with or without visual styles. This class cannot be inherited.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
| Name | Description | |
|---|---|---|
![]() ![]() | RenderMatchingApplicationState | Gets or sets a value indicating whether the renderer uses the application state to determine rendering style. |
| Name | Description | |
|---|---|---|
![]() ![]() | 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^, 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, 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^, 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. |
![]() ![]() | DrawParentBackground(Graphics^, Rectangle, Control^) | Draws the background of a control's parent in the specified area. |
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() ![]() | GetGlyphSize(Graphics^, CheckBoxState) | Returns the size of the check box glyph. |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() ![]() | IsBackgroundPartiallyTransparent(CheckBoxState) | Indicates whether the background of the check box has semitransparent or alpha-blended pieces. |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
The CheckBoxRenderer class provides a set of static methods that can be used to render a check box control. Rendering a control refers to drawing the user interface of a control. To draw a check box, use one of the DrawCheckBox methods. These methods provide a variety of options, such as drawing text or an image with the check box.
If visual styles are enabled in the operating system and visual styles are applied to the current application, DrawCheckBox will draw the check box with the current visual style. Otherwise, DrawCheckBox will draw the check box with the classic Windows style. This is useful if you are drawing a custom control that should automatically match the current visual style setting of the operating system.
This class wraps the functionality of a System.Windows.Forms.VisualStyles::VisualStyleRenderer that is set to one of the elements exposed by the System.Windows.Forms.VisualStyles::VisualStyleElement::Button::CheckBox class. For more information, see Rendering Controls with Visual Styles.
Visual styles are supported only on these platforms.
The following code example demonstrates how to write a custom control that uses the DrawCheckBox method to draw a check box that responds to mouse clicks.
#using <System.dll> #using <System.Drawing.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; using namespace System::Windows::Forms::VisualStyles; namespace CheckBoxRendererSample { ref class CustomCheckBox : Control { private: Rectangle textRectangleValue; Point clickedLocationValue; bool clicked; CheckBoxState state; public : CustomCheckBox() : Control() { this->textRectangleValue = Rectangle(); this->clickedLocationValue = Point(); this->clicked = false; this->state = CheckBoxState::UncheckedNormal; this->Location = Point(50, 50); this->Size = System::Drawing::Size(100, 20); this->Text = "Click here"; this->Font = SystemFonts::IconTitleFont; } // Calculate the text bounds, exluding the check box. Rectangle getTextRectangle() { Graphics ^g = this->CreateGraphics(); textRectangleValue.X = ClientRectangle.X + CheckBoxRenderer::GetGlyphSize(g, CheckBoxState::UncheckedNormal).Width; textRectangleValue.Y = ClientRectangle.Y; textRectangleValue.Width = ClientRectangle.Width - CheckBoxRenderer::GetGlyphSize(g, CheckBoxState::UncheckedNormal).Width; textRectangleValue.Height = ClientRectangle.Height; delete g; return textRectangleValue; } protected: // 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 hot state. virtual void OnMouseHover(EventArgs ^e) override { Control::OnMouseHover(e); state = clicked ? CheckBoxState::CheckedHot : CheckBoxState::UncheckedHot; Invalidate(); } // Draw the check box in the hot state. virtual void OnMouseUp(MouseEventArgs ^e) override { Control::OnMouseUp(e); this->OnMouseHover(e); } // Draw the check box in the unpressed state. virtual void OnMouseLeave(EventArgs ^e) override { Control::OnMouseLeave(e); state = clicked ? CheckBoxState::CheckedNormal : CheckBoxState::UncheckedNormal; Invalidate(); } }; ref class Form1: public Form { public: Form1() : Form() { CustomCheckBox ^CheckBox1 = gcnew CustomCheckBox(); Controls->Add(CheckBox1); if (Application::RenderWithVisualStyles) { this->Text = "Visual Styles Enabled"; } else { this->Text = "Visual Styles Disabled"; } } }; } [STAThread] int main() { // If you do not call EnableVisualStyles below, then // CheckBoxRenderer.DrawCheckBox automatically detects // this and draws the check box without visual styles. Application::EnableVisualStyles(); Application::Run(gcnew CheckBoxRendererSample::Form1()); }
Available since 2.0
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


