This topic has not yet been rated - Rate this topic

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 PaintEventArgs e, 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

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.