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)

[BrowsableAttribute(false)]
public Region Region { get; set; }

Property Value

Type: System.Drawing.Region

The window Region associated with the control.

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.

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);
}
Return to top
Show: