VisualStyleRenderer.DrawBackground Méthode

Définition

Dessine l’image d’arrière-plan de l’élément de style visuel actuel.

Surcharges

Nom Description
DrawBackground(IDeviceContext, Rectangle)

Dessine l’image d’arrière-plan de l’élément de style visuel actuel dans le rectangle englobant spécifié.

DrawBackground(IDeviceContext, Rectangle, Rectangle)

Dessine l’image d’arrière-plan de l’élément de style visuel actuel dans le rectangle englobant spécifié et rogné dans le rectangle de découpage spécifié.

DrawBackground(IDeviceContext, Rectangle)

Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs

Dessine l’image d’arrière-plan de l’élément de style visuel actuel dans le rectangle englobant spécifié.

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)

Paramètres

dc
IDeviceContext

Utilisé IDeviceContext pour dessiner l’image d’arrière-plan.

bounds
Rectangle

Dans Rectangle lequel l’image d’arrière-plan est dessinée.

Exceptions

dc a la valeur null.

Exemples

L’exemple de code suivant montre comment utiliser la DrawBackground(IDeviceContext, Rectangle) méthode pour dessiner un VisualStyleElement élément dans la méthode d’un OnPaint contrôle personnalisé. Cet exemple de code fait partie d’un exemple plus large fourni pour la vue d’ensemble de la VisualStyleRenderer classe.

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

Remarques

Cette méthode dessine l’arrière-plan de l’élément de style visuel actuel spécifié par les propriétés et Class les PartStatepropriétés.

Si le Width ou Height du rectangle spécifié par le bounds paramètre est inférieur à 0, la DrawBackground méthode retourne sans dessiner l’arrière-plan.

L’arrière-plan d’un élément de style visuel peut être un fichier bitmap ou une bordure remplie. Pour déterminer le type d’arrière-plan, appelez la GetEnumValue méthode avec une valeur d’argument de EnumProperty.BackgroundType. Pour déterminer si l’arrière-plan de l’élément s’adapte aux limites spécifiées, appelez la GetEnumValue méthode avec une valeur d’argument de EnumProperty.SizingType.

S’applique à

DrawBackground(IDeviceContext, Rectangle, Rectangle)

Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs

Dessine l’image d’arrière-plan de l’élément de style visuel actuel dans le rectangle englobant spécifié et rogné dans le rectangle de découpage spécifié.

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)

Paramètres

dc
IDeviceContext

Utilisé IDeviceContext pour dessiner l’image d’arrière-plan.

bounds
Rectangle

Dans Rectangle lequel l’image d’arrière-plan est dessinée.

clipRectangle
Rectangle

Qui Rectangle définit un rectangle de découpage pour l’opération de dessin.

Exceptions

dc a la valeur null.

Remarques

Cette méthode dessine l’arrière-plan de l’élément de style visuel actuel spécifié par les propriétés et Class les PartStatepropriétés. L’arrière-plan est clippé dans la zone spécifiée par le clipRectangle paramètre.

Si le ou Width du rectangle spécifié par l’un Height ou l’autre boundsclipRectangle des paramètres est inférieur à 0, la DrawBackground méthode retourne sans dessiner l’arrière-plan.

L’arrière-plan d’un élément de style visuel peut être un fichier bitmap ou une bordure remplie. Pour déterminer le type d’arrière-plan, appelez la GetEnumValue méthode avec une valeur d’argument de EnumProperty.BackgroundType. Pour déterminer si l’arrière-plan de l’élément s’adapte aux limites spécifiées, appelez la GetEnumValue méthode avec une valeur d’argument de EnumProperty.SizingType.

S’applique à