CheckBoxRenderer.DrawCheckBox 方法

定义

绘制复选框控件。

重载

名称 说明
DrawCheckBox(Graphics, Point, CheckBoxState)

绘制处于指定状态和位置的复选框控件。

DrawCheckBox(Graphics, Point, Rectangle, String, Font, Boolean, CheckBoxState)

使用指定的文本和可选焦点矩形在指定状态和位置绘制复选框控件。

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

使用指定的文本和文本格式以及可选的焦点矩形在指定状态和位置绘制复选框控件。

DrawCheckBox(Graphics, Point, Rectangle, String, Font, Image, Rectangle, Boolean, CheckBoxState)

使用指定的文本和图像以及可选的焦点矩形在指定状态和位置绘制复选框控件。

DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, CheckBoxState)

绘制处于指定状态和位置的复选框控件;具有指定文本、文本格式和图像;以及具有可选焦点矩形。

DrawCheckBox(Graphics, Point, CheckBoxState)

Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs

绘制处于指定状态和位置的复选框控件。

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)

参数

g
Graphics

Graphics用于绘制复选框的复选框。

glyphLocation
Point

Point 绘制复选框标志符号。

state
CheckBoxState

CheckBoxState指定复选框视觉状态的值之一。

注解

如果在操作系统中启用了视觉样式,并且视觉样式应用于当前应用程序,此方法将使用当前视觉样式绘制复选框。 否则,它将使用经典Windows样式绘制复选框。

适用于

DrawCheckBox(Graphics, Point, Rectangle, String, Font, Boolean, CheckBoxState)

Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs

使用指定的文本和可选焦点矩形在指定状态和位置绘制复选框控件。

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)

参数

g
Graphics

Graphics用于绘制复选框的复选框。

glyphLocation
Point

Point 绘制复选框标志符号。

textBounds
Rectangle

Rectangle 绘制 checkBoxText 的。

checkBoxText
String

String 用复选框绘制。

font
Font

Font要应用于checkBoxText的 。

focused
Boolean

true 绘制焦点矩形;否则,为 false.

state
CheckBoxState

CheckBoxState指定复选框视觉状态的值之一。

注解

如果在操作系统中启用了视觉样式,并且视觉样式应用于当前应用程序,此方法将使用当前视觉样式绘制复选框。 否则,它将使用经典Windows样式绘制复选框。

适用于

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

Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs

使用指定的文本和文本格式以及可选的焦点矩形在指定状态和位置绘制复选框控件。

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)

参数

g
Graphics

Graphics用于绘制复选框的复选框。

glyphLocation
Point

Point 绘制复选框标志符号。

textBounds
Rectangle

Rectangle 绘制 checkBoxText 的。

checkBoxText
String

String 用复选框绘制。

font
Font

Font要应用于checkBoxText的 。

flags
TextFormatFlags

值的按位组合 TextFormatFlags

focused
Boolean

true 绘制焦点矩形;否则,为 false.

state
CheckBoxState

CheckBoxState指定复选框视觉状态的值之一。

示例

下面的代码示例使用 DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Boolean, CheckBoxState) 自定义控件 OnPaint 方法中的方法在鼠标指针的位置确定的状态中绘制复选框。 该代码示例是 CheckBoxRenderer 类中的一个较大示例的一部分。

// 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

注解

如果在操作系统中启用了视觉样式,并且视觉样式应用于当前应用程序,此方法将使用当前视觉样式绘制复选框。 否则,它将使用经典Windows样式绘制复选框。

适用于

DrawCheckBox(Graphics, Point, Rectangle, String, Font, Image, Rectangle, Boolean, CheckBoxState)

Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs

使用指定的文本和图像以及可选的焦点矩形在指定状态和位置绘制复选框控件。

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)

参数

g
Graphics

Graphics用于绘制复选框的复选框。

glyphLocation
Point

Point 绘制复选框标志符号。

textBounds
Rectangle

Rectangle 绘制 checkBoxText 的。

checkBoxText
String

String 用复选框绘制。

font
Font

Font要应用于checkBoxText的 。

image
Image

Image 用复选框绘制。

imageBounds
Rectangle

表示 Rectangle 的维度的 image

focused
Boolean

true 绘制焦点矩形;否则,为 false.

state
CheckBoxState

CheckBoxState指定复选框视觉状态的值之一。

注解

如果在操作系统中启用了视觉样式,并且视觉样式应用于当前应用程序,此方法将使用当前视觉样式绘制复选框。 否则,它将使用经典Windows样式绘制复选框。

适用于

DrawCheckBox(Graphics, Point, Rectangle, String, Font, TextFormatFlags, Image, Rectangle, Boolean, CheckBoxState)

Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs
Source:
CheckBoxRenderer.cs

绘制处于指定状态和位置的复选框控件;具有指定文本、文本格式和图像;以及具有可选焦点矩形。

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)

参数

g
Graphics

Graphics用于绘制复选框的复选框。

glyphLocation
Point

Point 绘制复选框标志符号。

textBounds
Rectangle

Rectangle 绘制 checkBoxText 的。

checkBoxText
String

String 用复选框绘制。

font
Font

Font要应用于checkBoxText的 。

flags
TextFormatFlags

值的按位组合 TextFormatFlags

image
Image

Image 用复选框绘制。

imageBounds
Rectangle

表示 Rectangle 的维度的 image

focused
Boolean

true 绘制焦点矩形;否则,为 false.

state
CheckBoxState

CheckBoxState指定复选框视觉状态的值之一。

注解

如果在操作系统中启用了视觉样式,并且视觉样式应用于当前应用程序,此方法将使用当前视觉样式绘制复选框。 否则,它将使用经典Windows样式绘制复选框。

适用于