VisualStyleRenderer.DrawBackground 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
绘制当前视觉样式元素的背景图像。
重载
| DrawBackground(IDeviceContext, Rectangle) | 在指定边框内绘制当前视觉样式元素的背景图像。 | 
| DrawBackground(IDeviceContext, Rectangle, Rectangle) | 在指定边框内绘制当前视觉样式元素的背景图像,然后剪辑到指定的剪辑矩形。 | 
DrawBackground(IDeviceContext, Rectangle)
在指定边框内绘制当前视觉样式元素的背景图像。
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 -> unitPublic Sub DrawBackground (dc As IDeviceContext, bounds As Rectangle)参数
用于绘制背景图像的 IDeviceContext。
例外
              dc 为 null。
示例
下面的代码示例演示如何使用 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
注解
此方法绘制由 Class、 Part和 State 属性指定的当前视觉样式元素的背景。
              Width如果 参数指定的bounds矩形的 或 Height 小于 0,该方法DrawBackground将返回而不绘制背景。
视觉样式元素的背景可以是位图文件或填充边框。 若要确定背景类型,请使用 GetEnumValue 参数值 EnumProperty.BackgroundType调用 方法。 若要确定元素背景是否会缩放以适应指定的边界,请使用参数值 EnumProperty.SizingType调用 GetEnumValue 方法。
适用于
DrawBackground(IDeviceContext, Rectangle, Rectangle)
在指定边框内绘制当前视觉样式元素的背景图像,然后剪辑到指定的剪辑矩形。
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 -> unitPublic Sub DrawBackground (dc As IDeviceContext, bounds As Rectangle, clipRectangle As Rectangle)参数
用于绘制背景图像的 IDeviceContext。
例外
              dc 为 null。
注解
此方法绘制由 Class、 Part和 State 属性指定的当前视觉样式元素的背景。 背景将剪裁到 参数指定的 clipRectangle 区域。
              Width如果 或 Height 参数指定的bounds矩形的 或 clipRectangle 小于 0,该方法DrawBackground将返回而不绘制背景。
视觉样式元素的背景可以是位图文件或填充边框。 若要确定背景类型,请使用 GetEnumValue 参数值 EnumProperty.BackgroundType调用 方法。 若要确定元素背景是否会缩放以适应指定的边界,请使用参数值 EnumProperty.SizingType调用 GetEnumValue 方法。