VisualStyleRenderer.GetBackgroundRegion(IDeviceContext, Rectangle) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Retourne la région de l’arrière-plan de l’élément de style visuel actuel.
public:
System::Drawing::Region ^ GetBackgroundRegion(System::Drawing::IDeviceContext ^ dc, System::Drawing::Rectangle bounds);
public System.Drawing.Region GetBackgroundRegion(System.Drawing.IDeviceContext dc, System.Drawing.Rectangle bounds);
public System.Drawing.Region? GetBackgroundRegion(System.Drawing.IDeviceContext dc, System.Drawing.Rectangle bounds);
member this.GetBackgroundRegion : System.Drawing.IDeviceContext * System.Drawing.Rectangle -> System.Drawing.Region
Public Function GetBackgroundRegion (dc As IDeviceContext, bounds As Rectangle) As Region
Paramètres
Cette IDeviceContext opération sera utilisée.
- bounds
- Rectangle
Qui Rectangle contient l’ensemble de la zone d’arrière-plan de l’élément de style visuel actuel.
Retours
Qui Region contient l’arrière-plan de l’élément de style visuel actuel.
Exceptions
dc a la valeur null.
Exemples
L’exemple de code suivant montre comment utiliser la GetBackgroundRegion méthode dans un contrôle personnalisé. Cet exemple utilise GetBackgroundRegion pour obtenir l’élément Region de barre de titre de la fenêtre retourné par la VisualStyleElement.Window.Caption.Active propriété. Il Region est utilisé pour définir la Control.Region propriété du contrôle, afin que la barre de titre de la fenêtre apparaisse avec les angles arrondis définis par le style visuel Windows XP standard. Cet exemple de code fait partie d’un exemple plus large fourni pour la vue d’ensemble de la VisualStyleRenderer classe.
// Calculate and set the clipping region for the control
// so that the corners of the title bar are rounded.
private:
void SetClipRegion()
{
if (!Application::RenderWithVisualStyles)
{
return;
}
Graphics^ g = this->CreateGraphics();
// Get the current region for the window caption.
if (SetRenderer(windowElements["windowCaption"]))
{
System::Drawing::Region^ clipRegion =
renderer->GetBackgroundRegion(g,
elementRectangles["windowCaption"]);
// Get the client rectangle, but exclude the region
// of the window caption.
int height = (int)clipRegion->GetBounds(g).Height;
System::Drawing::Rectangle nonCaptionRect = Rectangle(
ClientRectangle.X, ClientRectangle.Y + height,
ClientRectangle.Width, ClientRectangle.Height - height);
// Add the rectangle to the caption region, and
// make this region the form's clipping region.
clipRegion->Union(nonCaptionRect);
this->Region = clipRegion;
}
}
// Calculate and set the clipping region for the control
// so that the corners of the title bar are rounded.
private void SetClipRegion()
{
if (!Application.RenderWithVisualStyles)
{
return;
}
using (Graphics g = this.CreateGraphics())
{
// Get the current region for the window caption.
if (SetRenderer(windowElements["windowCaption"]))
{
Region clipRegion = renderer.GetBackgroundRegion(
g, elementRectangles["windowCaption"]);
// Get the client rectangle, but exclude the region
// of the window caption.
int height = (int)clipRegion.GetBounds(g).Height;
Rectangle nonCaptionRect = new Rectangle(
ClientRectangle.X,
ClientRectangle.Y + height,
ClientRectangle.Width,
ClientRectangle.Height - height);
// Add the rectangle to the caption region, and
// make this region the form's clipping region.
clipRegion.Union(nonCaptionRect);
this.Region = clipRegion;
}
}
}
' Calculate and set the clipping region for the control
' so that the corners of the title bar are rounded.
Private Sub SetClipRegion()
If Not Application.RenderWithVisualStyles Then
Return
End If
Using g As Graphics = Me.CreateGraphics()
' Get the current region for the window caption.
If SetRenderer(windowElements("windowCaption")) Then
Dim clipRegion As Region = _
renderer.GetBackgroundRegion(g, _
elementRectangles("windowCaption"))
' Get the client rectangle, but exclude the
' region of the window caption.
Dim height As Integer = _
CInt(clipRegion.GetBounds(g).Height)
Dim nonCaptionRect As _
New Rectangle(ClientRectangle.X, _
ClientRectangle.Y + height, _
ClientRectangle.Width, _
ClientRectangle.Height - height)
' Add the rectangle to the caption region, and
' make this region the form's clipping region.
clipRegion.Union(nonCaptionRect)
Me.Region = clipRegion
End If
End Using
End Sub
Remarques
Cette méthode peut être utilisée pour obtenir l’élément Region de style visuel qui a des parties partiellement transparentes ou mélangées alpha dans son arrière-plan.