VisualStyleRenderer.DrawBackground Metode

Definisi

Gambar latar belakang elemen gaya visual saat ini.

Overload

Nama Deskripsi
DrawBackground(IDeviceContext, Rectangle)

Gambar latar belakang elemen gaya visual saat ini dalam persegi panjang pembatas yang ditentukan.

DrawBackground(IDeviceContext, Rectangle, Rectangle)

Gambar latar belakang elemen gaya visual saat ini dalam persegi panjang pembatas yang ditentukan dan diklip ke persegi panjang kliping yang ditentukan.

DrawBackground(IDeviceContext, Rectangle)

Sumber:
VisualStyleRenderer.cs
Sumber:
VisualStyleRenderer.cs
Sumber:
VisualStyleRenderer.cs
Sumber:
VisualStyleRenderer.cs
Sumber:
VisualStyleRenderer.cs

Gambar latar belakang elemen gaya visual saat ini dalam persegi panjang pembatas yang ditentukan.

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)

Parameter

dc
IDeviceContext

yang IDeviceContext digunakan untuk menggambar gambar latar belakang.

bounds
Rectangle

di Rectangle mana gambar latar belakang digambar.

Pengecualian

dc adalah null.

Contoh

Contoh kode berikut menunjukkan cara menggunakan DrawBackground(IDeviceContext, Rectangle) metode untuk menggambar VisualStyleElement dalam metode kontrol OnPaint kustom. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk VisualStyleRenderer gambaran umum kelas.

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

Keterangan

Metode ini menggambar latar belakang elemen gaya visual saat ini yang ditentukan oleh Classproperti , , Partdan State .

Width Jika atau Height persegi panjang yang ditentukan oleh bounds parameter kurang dari 0, DrawBackground metode akan kembali tanpa menggambar latar belakang.

Latar belakang elemen gaya visual bisa berupa file bitmap atau batas terisi. Untuk menentukan jenis latar belakang, panggil GetEnumValue metode dengan nilai argumen .EnumProperty.BackgroundType Untuk menentukan apakah latar belakang elemen akan diskalakan agar sesuai dengan batas yang ditentukan, panggil GetEnumValue metode dengan nilai argumen .EnumProperty.SizingType

Berlaku untuk

DrawBackground(IDeviceContext, Rectangle, Rectangle)

Sumber:
VisualStyleRenderer.cs
Sumber:
VisualStyleRenderer.cs
Sumber:
VisualStyleRenderer.cs
Sumber:
VisualStyleRenderer.cs
Sumber:
VisualStyleRenderer.cs

Gambar latar belakang elemen gaya visual saat ini dalam persegi panjang pembatas yang ditentukan dan diklip ke persegi panjang kliping yang ditentukan.

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)

Parameter

dc
IDeviceContext

yang IDeviceContext digunakan untuk menggambar gambar latar belakang.

bounds
Rectangle

di Rectangle mana gambar latar belakang digambar.

clipRectangle
Rectangle

Rectangle yang mendefinisikan persegi panjang kliping untuk operasi menggambar.

Pengecualian

dc adalah null.

Keterangan

Metode ini menggambar latar belakang elemen gaya visual saat ini yang ditentukan oleh Classproperti , , Partdan State . Latar belakang akan diklip ke area yang ditentukan oleh clipRectangle parameter .

Width Jika atau Height persegi panjang yang ditentukan oleh bounds parameter atau clipRectangle kurang dari 0, DrawBackground metode akan kembali tanpa menggambar latar belakang.

Latar belakang elemen gaya visual bisa berupa file bitmap atau batas terisi. Untuk menentukan jenis latar belakang, panggil GetEnumValue metode dengan nilai argumen .EnumProperty.BackgroundType Untuk menentukan apakah latar belakang elemen akan diskalakan agar sesuai dengan batas yang ditentukan, panggil GetEnumValue metode dengan nilai argumen .EnumProperty.SizingType

Berlaku untuk