次の方法で共有


Shape.Region プロパティ

更新 : 2007 年 11 月

ライン コントロールまたはシェイプ コントロールに関連付けられたウィンドウ領域を取得または設定します。

名前空間 :  Microsoft.VisualBasic.PowerPacks
アセンブリ :  Microsoft.VisualBasic.PowerPacks.Vs (Microsoft.VisualBasic.PowerPacks.Vs.dll 内)

構文

'宣言
<BrowsableAttribute(False)> _
Public Property Region As Region
'使用
Dim instance As Shape
Dim value As Region

value = instance.Region

instance.Region = value
[BrowsableAttribute(false)]
public Region Region { get; set; }
[BrowsableAttribute(false)]
public:
property Region^ Region {
    Region^ get ();
    void set (Region^ value);
}
public function get Region () : Region
public function set Region (value : Region)

プロパティ値

型 : System.Drawing.Region

コントロールに関連付けられたウィンドウ Region

解説

ウィンドウ領域は、オペレーティング システムで描画が有効になっているウィンドウ内のピクセルのコレクションです。オペレーティング システムは、ウィンドウのウィンドウ領域の外側にある部分は表示しません。コントロールの領域の座標は、コントロールのクライアント領域に対する相対座標ではなく、コントロールの左上隅に対する相対座標です。

Region プロパティを使用して RectangleShape を半透明の楕円に変更する例を次に示します。この例では、RectangleShape1 という名前の RectangleShape がフォームにあることが必要です。半透明の効果を表示するには、イメージをフォームの BackgroundImage プロパティに割り当てます。

Private Sub RectangleShape1_Paint(ByVal sender As Object, _
 ByVal e As System.Windows.Forms.PaintEventArgs) _
 Handles RectangleShape1.Paint

    Dim shapePath As New System.Drawing.Drawing2D.GraphicsPath

    ' Set a new rectangle to the same size as the RectangleShape's 
    ' ClientRectangle property.
    Dim newRectangle As Rectangle = RectangleShape1.ClientRectangle

    ' Decrease the size of the rectangle.
    newRectangle.Inflate(-10, -10)

    ' Draw the new rectangle's border.
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle)

    ' Create a semi-transparent brush.
    Dim br As New SolidBrush(Color.FromArgb(128, 0, 0, 255))

    ' Fill the new rectangle.
    e.Graphics.FillEllipse(br, newRectangle)
    'Increase the size of the rectangle to include the border.
    newRectangle.Inflate(1, 1)

    ' Create an oval region within the new rectangle.
    shapePath.AddEllipse(newRectangle)
    e.Graphics.DrawPath(Pens.Black, shapePath)

    ' Set the RectangleShape's Region property to the newly created 
    ' oval region.
    RectangleShape1.Region = New System.Drawing.Region(shapePath)
End Sub
private void rectangleShape1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{

    System.Drawing.Drawing2D.GraphicsPath shapePath = new System.Drawing.Drawing2D.GraphicsPath();

    // Set a new rectangle to the same size as the RectangleShape's 
    // ClientRectangle property.
    Rectangle newRectangle = rectangleShape1.ClientRectangle;

    // Decrease the size of the rectangle.
    newRectangle.Inflate(-10, -10);

    // Draw the new rectangle's border.
    e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

    // Create a semi-transparent brush.
    SolidBrush br = new SolidBrush(Color.FromArgb(128, 0, 0, 255));

    // Fill the new rectangle.
    e.Graphics.FillEllipse(br, newRectangle);
    //Increase the size of the rectangle to include the border.
    newRectangle.Inflate(1, 1);

    // Create an oval region within the new rectangle.
    shapePath.AddEllipse(newRectangle);
    e.Graphics.DrawPath(Pens.Black, shapePath);

    // Set the RectangleShape's Region property to the newly created 
    // oval region.
    rectangleShape1.Region = new System.Drawing.Region(shapePath);
}

アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

Shape クラス

Shape メンバ

Microsoft.VisualBasic.PowerPacks 名前空間

その他の技術情報

方法 : LineShape コントロールを使用して線を描画する (Visual Studio)

方法 : OvalShape コントロールおよび RectangleShape コントロールを使用して図形を描画する (Visual Studio)

ライン コントロールとシェイプ コントロールの概要 (Visual Studio)