Region.IsVisible Method (RectangleF)

 

Tests whether any portion of the specified RectangleF structure is contained within this Region.

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

public bool IsVisible(
	RectangleF rect
)

Parameters

rect
Type: System.Drawing.RectangleF

The RectangleF structure to test.

Return Value

Type: System.Boolean

true when any portion of rect is contained within this Region; otherwise, false.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates the first rectangle and draws it to the screen in blue.

  • Creates the second rectangle and draws it to the screen in red.

  • Creates a region from the first rectangle.

  • Determines if any portion of the rectangle intersects with the region.

  • Displays the true or false result on the screen.

Notice that the rectangle intersects the region, so the result is true.

public void IsVisible_RectF_Example(PaintEventArgs e)
{

    // Create the first rectangle and draw it to the screen in blue.
    Rectangle regionRect = new Rectangle(20, 20, 100, 100);
    e.Graphics.DrawRectangle(Pens.Blue, regionRect);

    // Create the second rectangle and draw it to the screen in red.
    RectangleF myRect = new RectangleF(90, 30, 100, 100);
    e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(myRect));

    // Create a region using the first rectangle.
    Region myRegion = new Region(regionRect);

    // Determine if myRect is contained in the region.
    bool contained = myRegion.IsVisible(myRect);

    // Display the result.
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.Black);
    e.Graphics.DrawString("contained = " + contained.ToString(),
        myFont,
        myBrush,
        new PointF(20, 140));
}

.NET Framework
Available since 1.1
Return to top
Show: