Язык

VisualStyleRenderer.DrawBackground Метод

Определение

Рисует фоновое изображение текущего элемента визуального стиля.

Перегрузки

Имя Описание
DrawBackground(IDeviceContext, Rectangle)

Рисует фоновое изображение текущего элемента визуального стиля в указанном ограничивающем прямоугольнике.

DrawBackground(IDeviceContext, Rectangle, Rectangle)

Рисует фоновое изображение текущего элемента визуального стиля в указанном ограничивающем прямоугольнике и обрезается к указанному прямоугольнику обрезки.

DrawBackground(IDeviceContext, Rectangle)

Исходный код:
VisualStyleRenderer.cs
Исходный код:
VisualStyleRenderer.cs
Исходный код:
VisualStyleRenderer.cs
Исходный код:
VisualStyleRenderer.cs
Исходный код:
VisualStyleRenderer.cs

Рисует фоновое изображение текущего элемента визуального стиля в указанном ограничивающем прямоугольнике.

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 , в котором рисуется фоновое изображение.

Исключения

dc равно null.

Примеры

В следующем примере кода показано, как использовать DrawBackground(IDeviceContext, Rectangle) метод для рисования VisualStyleElement в методе пользовательского элемента управления OnPaint . Этот пример кода является частью более крупного примера, предоставленного для 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

Комментарии

Этот метод рисует фон текущего элемента визуального стиля, заданного свойством ClassPart, и State свойствами.

Width Если или Height прямоугольник, указанный bounds параметром, меньше 0, DrawBackground метод возвращается без рисования фона.

Фон элемента визуального стиля может быть растровым файлом или заполненной границей. Чтобы определить тип фона, вызовите GetEnumValue метод со значением аргумента EnumProperty.BackgroundType. Чтобы определить, будет ли фон элемента масштабироваться в соответствии с указанными границами, вызовите GetEnumValue метод со значением аргумента EnumProperty.SizingType.

Применяется к

DrawBackground(IDeviceContext, Rectangle, Rectangle)

Исходный код:
VisualStyleRenderer.cs
Исходный код:
VisualStyleRenderer.cs
Исходный код:
VisualStyleRenderer.cs
Исходный код:
VisualStyleRenderer.cs
Исходный код:
VisualStyleRenderer.cs

Рисует фоновое изображение текущего элемента визуального стиля в указанном ограничивающем прямоугольнике и обрезается к указанному прямоугольнику обрезки.

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 определяющий прямоугольник вырезки для операции рисования.

Исключения

dc равно null.

Комментарии

Этот метод рисует фон текущего элемента визуального стиля, заданного свойством ClassPart, и State свойствами. Фон будет обрезана к области, указанной параметром clipRectangle .

Width Если прямоугольник, Height указанный bounds параметром или clipRectangle параметрами меньше 0, DrawBackground метод возвращается без рисования фона.

Фон элемента визуального стиля может быть растровым файлом или заполненной границей. Чтобы определить тип фона, вызовите GetEnumValue метод со значением аргумента EnumProperty.BackgroundType. Чтобы определить, будет ли фон элемента масштабироваться в соответствии с указанными границами, вызовите GetEnumValue метод со значением аргумента EnumProperty.SizingType.

Применяется к