VisualStyleRenderer.DrawBackground Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Desenha a imagem de fundo do elemento visual atual.
Sobrecargas
| Name | Description |
|---|---|
| DrawBackground(IDeviceContext, Rectangle) |
Desenha a imagem de fundo do elemento de estilo visual atual dentro do retângulo delimitador especificado. |
| DrawBackground(IDeviceContext, Rectangle, Rectangle) |
Desenha a imagem de fundo do elemento de estilo visual atual dentro do retângulo delimitador especificado e recortada ao retângulo de recorte especificado. |
DrawBackground(IDeviceContext, Rectangle)
Desenha a imagem de fundo do elemento de estilo visual atual dentro do retângulo delimitador especificado.
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)
Parâmetros
Foram IDeviceContext usados para desenhar a imagem de fundo.
Exceções
dc é null.
Exemplos
O seguinte exemplo de código demonstra como usar o DrawBackground(IDeviceContext, Rectangle) método para desenhar a VisualStyleElement dentro do método de OnPaint um controlo personalizado. Este exemplo de código faz parte de um exemplo maior fornecido para a VisualStyleRenderer visão geral da 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
Observações
Este método desenha o fundo do elemento de estilo visual atual especificado pelas Classpropriedades , Part, e State .
Se o Width ou Height do retângulo especificado pelo bounds parâmetro for menor que 0, o DrawBackground método retornará sem desenhar o fundo.
O fundo de um elemento de estilo visual pode ser um ficheiro bitmap ou uma borda preenchida. Para determinar o tipo de fundo, chame-se ao GetEnumValue método com um valor de argumento de EnumProperty.BackgroundType. Para determinar se o fundo do elemento irá escalar para se ajustar aos limites especificados, chame o GetEnumValue método com um valor de argumento de EnumProperty.SizingType.
Aplica-se a
DrawBackground(IDeviceContext, Rectangle, Rectangle)
Desenha a imagem de fundo do elemento de estilo visual atual dentro do retângulo delimitador especificado e recortada ao retângulo de recorte especificado.
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)
Parâmetros
Foram IDeviceContext usados para desenhar a imagem de fundo.
Exceções
dc é null.
Observações
Este método desenha o fundo do elemento de estilo visual atual especificado pelas Classpropriedades , Part, e State . O fundo será recortado à área especificada pelo clipRectangle parâmetro.
Se o Width ou Height do retângulo especificado por qualquer um dos bounds parâmetros for clipRectangle menor que 0, o DrawBackground método retornará sem desenhar o fundo.
O fundo de um elemento de estilo visual pode ser um ficheiro bitmap ou uma borda preenchida. Para determinar o tipo de fundo, chame-se ao GetEnumValue método com um valor de argumento de EnumProperty.BackgroundType. Para determinar se o fundo do elemento irá escalar para se ajustar aos limites especificados, chame o GetEnumValue método com um valor de argumento de EnumProperty.SizingType.