VisualStyleRenderer.DrawBackground メソッド

定義

現在の visual スタイル要素の背景画像を描画します。

オーバーロード

名前 説明
DrawBackground(IDeviceContext, Rectangle)

指定した外接する四角形内に、現在の visual スタイル要素の背景イメージを描画します。

DrawBackground(IDeviceContext, Rectangle, Rectangle)

指定した外接する四角形内に現在の visual スタイル要素の背景画像を描画し、指定したクリッピング四角形にクリップします。

DrawBackground(IDeviceContext, Rectangle)

指定した外接する四角形内に、現在の visual スタイル要素の背景イメージを描画します。

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

注釈

このメソッドは、 ClassPart、および State プロパティで指定された現在の visual スタイル要素の背景を描画します。

bounds パラメーターで指定された四角形のWidthまたはHeightが 0 未満の場合、DrawBackground メソッドは背景を描画せずに戻ります。

visual スタイル要素の背景には、ビットマップ ファイルまたは塗りつぶされた境界線を指定できます。 背景の型を確認するには、引数値が EnumProperty.BackgroundTypeGetEnumValue メソッドを呼び出します。 要素の背景が指定された境界に合わせてスケーリングされるかどうかを判断するには、引数値が EnumProperty.SizingTypeGetEnumValue メソッドを呼び出します。

適用対象

DrawBackground(IDeviceContext, Rectangle, Rectangle)

指定した外接する四角形内に現在の visual スタイル要素の背景画像を描画し、指定したクリッピング四角形にクリップします。

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です。

注釈

このメソッドは、 ClassPart、および State プロパティで指定された現在の visual スタイル要素の背景を描画します。 背景は、 clipRectangle パラメーターで指定された領域にクリップされます。

boundsパラメーターまたはclipRectangle パラメーターで指定された四角形のWidthまたはHeightが 0 未満の場合、DrawBackground メソッドは背景を描画せずに戻ります。

visual スタイル要素の背景には、ビットマップ ファイルまたは塗りつぶされた境界線を指定できます。 背景の型を確認するには、引数値が EnumProperty.BackgroundTypeGetEnumValue メソッドを呼び出します。 要素の背景が指定された境界に合わせてスケーリングされるかどうかを判断するには、引数値が EnumProperty.SizingTypeGetEnumValue メソッドを呼び出します。

適用対象