VisualStyleRenderer.GetBackgroundRegion メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > VisualStyleRenderer.GetBackgroundRegion メソッドの意味・解説 

VisualStyleRenderer.GetBackgroundRegion メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

現在の visual スタイル要素の背景領域を返します。

名前空間: System.Windows.Forms.VisualStyles
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Function GetBackgroundRegion ( _
    dc As IDeviceContext, _
    bounds As Rectangle _
) As Region
Dim instance As VisualStyleRenderer
Dim dc As IDeviceContext
Dim bounds As Rectangle
Dim returnValue As Region

returnValue = instance.GetBackgroundRegion(dc, bounds)
public Region GetBackgroundRegion (
    IDeviceContext dc,
    Rectangle bounds
)
public:
Region^ GetBackgroundRegion (
    IDeviceContext^ dc, 
    Rectangle bounds
)
public Region GetBackgroundRegion (
    IDeviceContext dc, 
    Rectangle bounds
)
public function GetBackgroundRegion (
    dc : IDeviceContext, 
    bounds : Rectangle
) : Region

パラメータ

dc

この操作で使用する IDeviceContext。

bounds

現在の visual スタイル要素の背景領域全体を含む Rectangle。

戻り値
現在の visual スタイル要素の背景を含む Region。

例外例外
例外の種類条件

ArgumentNullException

dc が null 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次のコード例では、カスタム コントロールで GetBackgroundRegion メソッドを使用する方法を示します。この例では、GetBackgroundRegion を使用して、VisualStyleElement.Window.Caption.Active プロパティが返すウィンドウ タイトル バー要素の Region を取得します。また、この Region を使用して、コントロールの Control.Region プロパティを設定し、標準 Windows XP visual スタイルによって定義されている角の丸いウィンドウ タイトル バーが表示されるようにします。このコード例は VisualStyleRenderer クラスの概要で取り上げているコード例の一部分です。

' 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
// 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:
    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;
        }

    }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
VisualStyleRenderer クラス
VisualStyleRenderer メンバ
System.Windows.Forms.VisualStyles 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

VisualStyleRenderer.GetBackgroundRegion メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



VisualStyleRenderer.GetBackgroundRegion メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS