Shape.Region 属性

获取或设置窗口区域与 line 或 shape 控件。

命名空间:  Microsoft.VisualBasic.PowerPacks
程序集:  Microsoft.VisualBasic.PowerPacks.Vs(在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

语法

声明
<BrowsableAttribute(False)> _
Public Property Region As Region
[BrowsableAttribute(false)]
public Region Region { get; set; }
[BrowsableAttribute(false)]
public:
property Region^ Region {
    Region^ get ();
    void set (Region^ value);
}
[<BrowsableAttribute(false)>]
member Region : Region with get, set
function get Region () : Region
function set Region (value : Region)

属性值

类型:System.Drawing.Region
与控件关联的窗口 Region

备注

windows 区域 是像素的集合操作系统启用绘制窗口的。 操作系统未显示在窗口边界之外窗口的任何部分。 控件区域的坐标是相对于控件左上角的,而不是相对于控件工作区的。

示例

下面的示例演示如何使用 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);
}

.NET Framework 安全性

请参见

参考

Shape 类

Microsoft.VisualBasic.PowerPacks 命名空间

其他资源

如何:使用 LineShape 控件绘制直线 (Visual Studio)

如何:使用 OvalShape 和 RectangleShape 控件绘制形状 (Visual Studio)

Line 和 Shape 控件简介 (Visual Studio)