VisualStyleRenderer.GetBackgroundRegion(IDeviceContext, Rectangle) Metoda

Definice

Vrátí oblast pozadí aktuálního prvku vizuálního stylu.

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

Parametry

dc
IDeviceContext

Tato IDeviceContext operace se použije.

bounds
Rectangle

A Rectangle , který obsahuje celou oblast pozadí aktuálního prvku vizuálního stylu.

Návraty

Region

Obsahuje Region pozadí aktuálního prvku vizuálního stylu.

Výjimky

dc je null.

Příklady

Následující příklad kódu ukazuje, jak použít metodu GetBackgroundRegion ve vlastním ovládacím prvku. Tento příklad používá GetBackgroundRegion k získání Region elementu záhlaví okna vráceného VisualStyleElement.Window.Caption.Active vlastností. Používá Region se k nastavení Control.Region vlastnosti ovládacího prvku, aby se záhlaví okna zobrazilo se zaoblenými rohy definovanými standardním vizuálním stylem Windows XP. Tento příklad kódu je součástí většího příkladu poskytnutého VisualStyleRenderer pro přehled třídy.

    // 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

Poznámky

Tuto metodu lze použít k získání Region elementu vizuálního stylu, který má částečně průhledné nebo alfa-blended části na pozadí.

Platí pro