CheckBoxRenderer.GetGlyphSize(Graphics, CheckBoxState) 方法

定义

返回复选框标志符号的大小。

public:
 static System::Drawing::Size GetGlyphSize(System::Drawing::Graphics ^ g, System::Windows::Forms::VisualStyles::CheckBoxState state);
public static System.Drawing.Size GetGlyphSize (System.Drawing.Graphics g, System.Windows.Forms.VisualStyles.CheckBoxState state);
static member GetGlyphSize : System.Drawing.Graphics * System.Windows.Forms.VisualStyles.CheckBoxState -> System.Drawing.Size
Public Shared Function GetGlyphSize (g As Graphics, state As CheckBoxState) As Size

参数

g
Graphics

此操作将使用的 Graphics

state
CheckBoxState

CheckBoxState 值之一,它指定复选框的可视状态。

返回

表示复选框标志符号大小的 Size

示例

下面的代码示例使用 GetGlyphSize 方法确定复选框文本的边界。 此代码示例是为 CheckBoxRenderer 类提供的一个更大示例的一部分。

// 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;
}
// Calculate the text bounds, exluding the check box.
public Rectangle TextRectangle
{
    get
    {
        using (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;
        }

        return textRectangleValue;
    }
}
' Calculate the text bounds, exluding the check box.
Public ReadOnly Property TextRectangle() As Rectangle
    Get
        Using g As Graphics = Me.CreateGraphics()
            With textRectangleValue
                .X = Me.ClientRectangle.X + _
                    CheckBoxRenderer.GetGlyphSize(g, _
                    CheckBoxState.UncheckedNormal).Width
                .Y = Me.ClientRectangle.Y
                .Width = Me.ClientRectangle.Width - _
                    CheckBoxRenderer.GetGlyphSize(g, _
                    CheckBoxState.UncheckedNormal).Width
                .Height = Me.ClientRectangle.Height
            End With
        End Using
        Return textRectangleValue
    End Get
End Property

注解

复选框字形的大小由操作系统的当前视觉样式决定。

适用于