VisualStyleRenderer.DrawBackground Metoda

Definicja

Rysuje obraz tła bieżącego elementu stylu wizualizacji.

Przeciążenia

DrawBackground(IDeviceContext, Rectangle)

Rysuje obraz tła bieżącego elementu stylu wizualizacji w określonym prostokącie ograniczenia.

DrawBackground(IDeviceContext, Rectangle, Rectangle)

Rysuje obraz tła bieżącego elementu stylu wizualizacji w określonym prostokącie ograniczenia i przycięty do określonego prostokąta wycinkowego.

DrawBackground(IDeviceContext, Rectangle)

Rysuje obraz tła bieżącego elementu stylu wizualizacji w określonym prostokącie ograniczenia.

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)

Parametry

dc
IDeviceContext

Obiekt IDeviceContext używany do rysowania obrazu tła.

bounds
Rectangle

Element Rectangle , w którym jest rysowany obraz tła.

Wyjątki

dc to null.

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą DrawBackground(IDeviceContext, Rectangle) metody narysować VisualStyleElement obiekt w metodzie niestandardowej kontrolki OnPaint . Ten przykład kodu jest częścią większego przykładu udostępnionego VisualStyleRenderer do omówienia klasy.

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

Uwagi

Ta metoda rysuje tło bieżącego elementu stylu wizualizacji określonego Classprzez właściwości , Parti State .

Width Jeśli wartość lub Height prostokąta określonego bounds przez parametr jest mniejsza niż 0, DrawBackground metoda zwróci wartość bez rysowania tła.

Tło elementu stylu wizualizacji może być plikiem mapy bitowej lub wypełnionym obramowaniem. Aby określić typ tła, wywołaj metodę GetEnumValue z wartością argumentu EnumProperty.BackgroundType. Aby określić, czy tło elementu będzie skalowane w celu dopasowania do określonych granic, wywołaj GetEnumValue metodę z wartością argumentu EnumProperty.SizingType.

Dotyczy

DrawBackground(IDeviceContext, Rectangle, Rectangle)

Rysuje obraz tła bieżącego elementu stylu wizualizacji w określonym prostokącie ograniczenia i przycięty do określonego prostokąta wycinkowego.

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)

Parametry

dc
IDeviceContext

Obiekt IDeviceContext używany do rysowania obrazu tła.

bounds
Rectangle

Element Rectangle , w którym jest rysowany obraz tła.

clipRectangle
Rectangle

Obiekt Rectangle definiujący przycinanie prostokąta dla operacji rysunku.

Wyjątki

dc to null.

Uwagi

Ta metoda rysuje tło bieżącego elementu stylu wizualizacji określonego Classprzez właściwości , Parti State . Tło zostanie przycięte do obszaru określonego clipRectangle przez parametr .

Width Jeśli wartość lub Height prostokąta określonego przez bounds parametry lub clipRectangle jest mniejsza niż 0, DrawBackground metoda zwróci wartość bez rysowania tła.

Tło elementu stylu wizualizacji może być plikiem mapy bitowej lub wypełnionym obramowaniem. Aby określić typ tła, wywołaj metodę GetEnumValue z wartością argumentu EnumProperty.BackgroundType. Aby określić, czy tło elementu będzie skalowane w celu dopasowania do określonych granic, wywołaj GetEnumValue metodę z wartością argumentu EnumProperty.SizingType.

Dotyczy