CheckBoxRenderer.GetGlyphSize(Graphics, CheckBoxState) 方法

定義

傳回核取方塊圖像 (Glyph) 的大小。

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

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

備註

核取方塊圖像的大小取決於作業系統的目前視覺樣式。

適用於