VisualStyleRenderer.GetBackgroundRegion(IDeviceContext, Rectangle) 메서드

정의

현재 비주얼 스타일 요소의 배경 영역을 반환합니다.

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

매개 변수

dc
IDeviceContext

이 작업에서 사용할 IDeviceContext입니다.

bounds
Rectangle

현재 비주얼 스타일 요소의 전체 배경 영역을 포함하는 Rectangle입니다.

반환

Region

현재 비주얼 스타일 요소의 배경을 포함하는 Region입니다.

예외

dc이(가) null인 경우

예제

다음 코드 예제에서는 사용자 지정 컨트롤에서 메서드를 GetBackgroundRegion 사용 하는 방법을 보여 줍니다. 이 예제에서는 속성에서 반환 VisualStyleElement.Window.Caption.ActiveRegion 창 제목 표시줄 요소를 가져오는 데 사용합니다GetBackgroundRegion. 이 Region 컨트롤의 Control.Region 속성을 설정 하는 데 사용 됩니다 창 제목 표시줄 표준 Windows XP 비주얼 스타일에 의해 정의 된 둥근된 모서리와 함께 표시 됩니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 VisualStyleRenderer 클래스 개요입니다.

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

설명

이 메서드는 부분적으로 투명하거나 알파 혼합된 부분이 배경에 있는 비주얼 스타일 요소를 가져오는 Region 데 사용할 수 있습니다.

적용 대상