VisualStyleRenderer.DrawBackground 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
繪製當前視覺風格元素的背景影像。
多載
| 名稱 | Description |
|---|---|
| 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 -> unit
Public Sub DrawBackground (dc As IDeviceContext, bounds As Rectangle)
參數
他們 IDeviceContext 用來繪製背景圖。
例外狀況
dc 是 null。
範例
以下程式碼範例示範如何利用該DrawBackground(IDeviceContext, Rectangle)方法在自訂控制項的方法VisualStyleElement中繪製 aOnPaint。 這個程式碼範例是為類別概述提供 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參數指定的Height矩形的 or bounds 小於 0,DrawBackground方法將返回而不繪製背景。
視覺風格元素的背景可以是點陣圖檔案或填充邊框。 要確定背景型別,呼叫 GetEnumValue 參數值 EnumProperty.BackgroundType為 的方法。 為了判斷元素背景是否能隨指定界限擴展,呼叫 GetEnumValue 參數值 EnumProperty.SizingType為的方法。
適用於
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 -> unit
Public Sub DrawBackground (dc As IDeviceContext, bounds As Rectangle, clipRectangle As Rectangle)
參數
他們 IDeviceContext 用來繪製背景圖。
例外狀況
dc 是 null。
備註
此方法繪製由 Class、 Part及 State 屬性指定的當前視覺樣式元素的背景。 背景會被裁剪到參數 clipRectangle 指定的區域。
如果Width由 或Height參數指定的bounds矩形的 or clipRectangle 小於 0,DrawBackground該方法將返回而不繪製背景。
視覺風格元素的背景可以是點陣圖檔案或填充邊框。 要確定背景型別,呼叫 GetEnumValue 參數值 EnumProperty.BackgroundType為 的方法。 為了判斷元素背景是否能隨指定界限擴展,呼叫 GetEnumValue 參數值 EnumProperty.SizingType為的方法。