Share via


Shape.Region Property

 

Gets or sets the window region associated with a line or shape control.

Namespace:   Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

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

Property Value

Type: System.Drawing.Region

The window Region associated with the control.

Remarks

The window region is a collection of pixels in the window where the operating system enables drawing. The operating system does not display any part of a window that is outside the window region. The coordinates of a control's region are relative to the upper-left corner of the control, not the client area of the control.

Examples

The following example demonstrates how to use the Region property to change a RectangleShape into a semi-transparent oval. This example requires that you have a RectangleShape named RectangleShape1 on a form. To see the semi-transparent effect, assign an image to the BackgroundImage property of the form.

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);
}
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

See Also

Shape Class
Microsoft.VisualBasic.PowerPacks Namespace
How to: Draw Lines with the LineShape Control (Visual Studio)
How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)
Introduction to the Line and Shape Controls (Visual Studio)

Return to top