VisualStyleRenderer.DrawBackground 方法

定義

繪製目前視覺化樣式項目的背景影像。

多載

DrawBackground(IDeviceContext, Rectangle)

在指定的週框內繪製目前視覺化樣式項目的背景影像。

DrawBackground(IDeviceContext, Rectangle, Rectangle)

在指定的週框內繪製目前視覺化樣式項目的背景影像並裁剪至指定的裁剪方框。

DrawBackground(IDeviceContext, Rectangle)

在指定的週框內繪製目前視覺化樣式項目的背景影像。

public:
 void DrawBackground(System::Drawing::IDeviceContext ^ dc, System::Drawing::Rectangle bounds);
public void DrawBackground (System.Drawing.IDeviceContext dc, System.Drawing.Rectangle bounds);
member this.DrawBackground : System.Drawing.IDeviceContext * System.Drawing.Rectangle -> unit
Public Sub DrawBackground (dc As IDeviceContext, bounds As Rectangle)

參數

dc
IDeviceContext

IDeviceContext,用於繪製背景影像。

bounds
Rectangle

Rectangle,在其中繪製背景影像。

例外狀況

dcnull

範例

下列程式碼範例示範如何使用 DrawBackground(IDeviceContext, Rectangle) 方法,在自訂控制項 OnPaint 的 方法內繪製 VisualStyleElement 。 此程式碼範例是類別概觀所提供較大範例的 VisualStyleRenderer 一部分。

protected:
    virtual void OnPaint(PaintEventArgs^ e) override
    {
        __super::OnPaint(e);

        // Ensure that visual styles are supported.
        if (!Application::RenderWithVisualStyles)
        {
            this->Text = "Visual styles are not enabled.";
            TextRenderer::DrawText(e->Graphics, this->Text,
                this->Font, this->Location, this->ForeColor);
            return;
        }

        // Set the clip region to define the curved corners
        // of the caption.
        SetClipRegion();

        // Draw each part of the window.
        for each(KeyValuePair<String^, VisualStyleElement^>^ entry
            in windowElements)
        {
            if (SetRenderer(entry->Value))
            {
                renderer->DrawBackground(e->Graphics,
                    elementRectangles[entry->Key]);
            }
        }

        // Draw the caption text.
        TextRenderer::DrawText(e->Graphics, this->Text, this->Font,
            elementRectangles["windowCaption"], Color::White,
            TextFormatFlags::VerticalCenter |
            TextFormatFlags::HorizontalCenter);
    }
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    // Ensure that visual styles are supported.
    if (!Application.RenderWithVisualStyles)
    {
        this.Text = "Visual styles are not enabled.";
        TextRenderer.DrawText(e.Graphics, this.Text,
            this.Font, this.Location, this.ForeColor);
        return;
    }

    // Set the clip region to define the curved corners 
    // of the caption.
    SetClipRegion();

    // Draw each part of the window.
    foreach (KeyValuePair<string, VisualStyleElement> entry
        in windowElements)
    {
        if (SetRenderer(entry.Value))
        {
            renderer.DrawBackground(e.Graphics,
                elementRectangles[entry.Key]);
        }
    }

    // Draw the caption text.
    TextRenderer.DrawText(e.Graphics, this.Text, this.Font,
        elementRectangles["windowCaption"], Color.White,
        TextFormatFlags.VerticalCenter |
        TextFormatFlags.HorizontalCenter);
}
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)

    ' Ensure that visual styles are supported.
    If Not Application.RenderWithVisualStyles Then
        Me.Text = "Visual styles are not enabled."
        TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, _
            Me.Location, Me.ForeColor)
        Return
    End If

    ' Set the clip region to define the curved corners of 
    ' the caption.
    SetClipRegion()

    ' Draw each part of the window.
    Dim entry As KeyValuePair(Of String, VisualStyleElement)
    For Each entry In windowElements
        If SetRenderer(entry.Value) Then
            renderer.DrawBackground(e.Graphics, _
                elementRectangles(entry.Key))
        End If
    Next entry

    ' Draw the caption text.
    TextRenderer.DrawText(e.Graphics, Me.Text, Me.Font, _
        elementRectangles("windowCaption"), Color.White, _
        TextFormatFlags.VerticalCenter Or _
        TextFormatFlags.HorizontalCenter)
End Sub

備註

這個方法會繪製 、 PartState 屬性所 Class 指定目前視覺化樣式專案的背景。

Width如果 參數指定的 boundsHeight 矩形小於 0, DrawBackground 則方法會傳回而不繪製背景。

視覺化樣式專案的背景可以是點陣圖檔案或填滿框線。 若要判斷背景類型,請使用 的引數值 EnumProperty.BackgroundType 呼叫 GetEnumValue 方法。 若要判斷專案背景是否會調整以符合指定的界限,請使用 的引數值 EnumProperty.SizingType 呼叫 GetEnumValue 方法。

適用於

DrawBackground(IDeviceContext, Rectangle, Rectangle)

在指定的週框內繪製目前視覺化樣式項目的背景影像並裁剪至指定的裁剪方框。

public:
 void DrawBackground(System::Drawing::IDeviceContext ^ dc, System::Drawing::Rectangle bounds, System::Drawing::Rectangle clipRectangle);
public void DrawBackground (System.Drawing.IDeviceContext dc, System.Drawing.Rectangle bounds, System.Drawing.Rectangle clipRectangle);
member this.DrawBackground : System.Drawing.IDeviceContext * System.Drawing.Rectangle * System.Drawing.Rectangle -> unit
Public Sub DrawBackground (dc As IDeviceContext, bounds As Rectangle, clipRectangle As Rectangle)

參數

dc
IDeviceContext

IDeviceContext,用於繪製背景影像。

bounds
Rectangle

Rectangle,在其中繪製背景影像。

clipRectangle
Rectangle

Rectangle,定義繪製作業的裁剪方框。

例外狀況

dcnull

備註

這個方法會繪製 、 PartState 屬性所 Class 指定目前視覺化樣式專案的背景。 背景會裁剪到 參數所 clipRectangle 指定的區域。

Width如果 或 clipRectangle 參數所 bounds 指定的 或 矩形的 或 Height 小於 0, DrawBackground 則方法會傳回而不繪製背景。

視覺化樣式專案的背景可以是點陣圖檔案或填滿框線。 若要判斷背景類型,請使用 的引數值 EnumProperty.BackgroundType 呼叫 GetEnumValue 方法。 若要判斷專案背景是否會調整以符合指定的界限,請使用 的引數值 EnumProperty.SizingType 呼叫 GetEnumValue 方法。

適用於