Rectangle.IsEmpty Property

 

Tests whether all numeric properties of this Rectangle have values of zero.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

[BrowsableAttribute(false)]
public bool IsEmpty { get; }

Property Value

Type: System.Boolean

This property returns true if the Width, Height, X, and Y properties of this Rectangle all have values of zero; otherwise, false.

The following code example demonstrates the Intersect, IsEmpty and the IntersectsWith members. This example should be used with a Windows Form. Paste this code into a form and call this method when handling the form's Paint event, passing e as PaintEventArgs.

private void InstanceRectangleIntersection(PaintEventArgs e)
{

    Rectangle rectangle1 = new Rectangle(50, 50, 200, 100);
    Rectangle rectangle2 = new Rectangle(70, 20, 100, 200);

    e.Graphics.DrawRectangle(Pens.Black, rectangle1);
    e.Graphics.DrawRectangle(Pens.Red, rectangle2);

    if (rectangle1.IntersectsWith(rectangle2))
    {
        rectangle1.Intersect(rectangle2);
        if (!rectangle1.IsEmpty)
        {
            e.Graphics.FillRectangle(Brushes.Green, rectangle1);
        }
    }
}

.NET Framework
Available since 1.1
Return to top
Show: