VisualStyleRenderer.GetBackgroundRegion(IDeviceContext, Rectangle) Metodo

Definizione

Restituisce l'area per lo sfondo dell'elemento dello stile di visualizzazione corrente.

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

Parametri

dc
IDeviceContext

Oggetto IDeviceContext utilizzato da questa operazione.

bounds
Rectangle

Struttura Rectangle contenente l'intera area dello sfondo per l'elemento dello stile di visualizzazione corrente.

Restituisce

Struttura Region contenente lo sfondo dell'elemento dello stile di visualizzazione corrente.

Eccezioni

dc è null.

Esempio

Nell'esempio di codice seguente viene illustrato come usare il GetBackgroundRegion metodo in un controllo personalizzato. In questo esempio viene GetBackgroundRegion utilizzato per ottenere l'elemento Region della barra del titolo della finestra restituito dalla VisualStyleElement.Window.Caption.Active proprietà . Viene Region utilizzato per impostare la Control.Region proprietà del controllo, in modo che la barra del titolo della finestra venga visualizzata con gli angoli arrotondati definiti dallo stile di visualizzazione standard di Windows XP. Questo esempio di codice fa parte di un esempio più ampio fornito per la panoramica della 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

Commenti

Questo metodo può essere usato per ottenere l'oggetto Region di un elemento dello stile di visualizzazione con parti parzialmente trasparenti o combinate alfa nello sfondo.

Si applica a