0 out of 3 rated this helpful - Rate this topic

Region Class

Describes the interior of a graphics shape composed of rectangles and paths. This class cannot be inherited.

System.Object
  System.MarshalByRefObject
    System.Drawing.Region

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)
public sealed class Region : MarshalByRefObject, 
	IDisposable

The Region type exposes the following members.

  Name Description
Public method Region() Initializes a new Region.
Public method Region(GraphicsPath) Initializes a new Region with the specified GraphicsPath.
Public method Region(Rectangle) Initializes a new Region from the specified Rectangle structure.
Public method Region(RectangleF) Initializes a new Region from the specified RectangleF structure.
Public method Region(RegionData) Initializes a new Region from the specified data.
Top
  Name Description
Public method Clone Creates an exact copy of this Region.
Public method Complement(GraphicsPath) Updates this Region to contain the portion of the specified GraphicsPath that does not intersect with this Region.
Public method Complement(Rectangle) Updates this Region to contain the portion of the specified Rectangle structure that does not intersect with this Region.
Public method Complement(RectangleF) Updates this Region to contain the portion of the specified RectangleF structure that does not intersect with this Region.
Public method Complement(Region) Updates this Region to contain the portion of the specified Region that does not intersect with this Region.
Public method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Dispose Releases all resources used by this Region.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method Equals(Region, Graphics) Tests whether the specified Region is identical to this Region on the specified drawing surface.
Public method Exclude(GraphicsPath) Updates this Region to contain only the portion of its interior that does not intersect with the specified GraphicsPath.
Public method Exclude(Rectangle) Updates this Region to contain only the portion of its interior that does not intersect with the specified Rectangle structure.
Public method Exclude(RectangleF) Updates this Region to contain only the portion of its interior that does not intersect with the specified RectangleF structure.
Public method Exclude(Region) Updates this Region to contain only the portion of its interior that does not intersect with the specified Region.
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Static member FromHrgn Initializes a new Region from a handle to the specified existing GDI region.
Public method GetBounds Gets a RectangleF structure that represents a rectangle that bounds this Region on the drawing surface of a Graphics object.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetHrgn Returns a Windows handle to this Region in the specified graphics context.
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method GetRegionData Returns a RegionData that represents the information that describes this Region.
Public method GetRegionScans Returns an array of RectangleF structures that approximate this Region after the specified matrix transformation is applied.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method Intersect(GraphicsPath) Updates this Region to the intersection of itself with the specified GraphicsPath.
Public method Intersect(Rectangle) Updates this Region to the intersection of itself with the specified Rectangle structure.
Public method Intersect(RectangleF) Updates this Region to the intersection of itself with the specified RectangleF structure.
Public method Intersect(Region) Updates this Region to the intersection of itself with the specified Region.
Public method IsEmpty Tests whether this Region has an empty interior on the specified drawing surface.
Public method IsInfinite Tests whether this Region has an infinite interior on the specified drawing surface.
Public method IsVisible(Point) Tests whether the specified Point structure is contained within this Region.
Public method IsVisible(PointF) Tests whether the specified PointF structure is contained within this Region.
Public method IsVisible(Rectangle) Tests whether any portion of the specified Rectangle structure is contained within this Region.
Public method IsVisible(RectangleF) Tests whether any portion of the specified RectangleF structure is contained within this Region.
Public method IsVisible(Point, Graphics) Tests whether the specified Point structure is contained within this Region when drawn using the specified Graphics.
Public method IsVisible(PointF, Graphics) Tests whether the specified PointF structure is contained within this Region when drawn using the specified Graphics.
Public method IsVisible(Rectangle, Graphics) Tests whether any portion of the specified Rectangle structure is contained within this Region when drawn using the specified Graphics.
Public method IsVisible(RectangleF, Graphics) Tests whether any portion of the specified RectangleF structure is contained within this Region when drawn using the specified Graphics.
Public method IsVisible(Single, Single) Tests whether the specified point is contained within this Region.
Public method IsVisible(Int32, Int32, Graphics) Tests whether the specified point is contained within this Region object when drawn using the specified Graphics object.
Public method IsVisible(Single, Single, Graphics) Tests whether the specified point is contained within this Region when drawn using the specified Graphics.
Public method IsVisible(Int32, Int32, Int32, Int32) Tests whether any portion of the specified rectangle is contained within this Region.
Public method IsVisible(Single, Single, Single, Single) Tests whether any portion of the specified rectangle is contained within this Region.
Public method IsVisible(Int32, Int32, Int32, Int32, Graphics) Tests whether any portion of the specified rectangle is contained within this Region when drawn using the specified Graphics.
Public method IsVisible(Single, Single, Single, Single, Graphics) Tests whether any portion of the specified rectangle is contained within this Region when drawn using the specified Graphics.
Public method MakeEmpty Initializes this Region to an empty interior.
Public method MakeInfinite Initializes this Region object to an infinite interior.
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public method ReleaseHrgn Releases the handle of the Region.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Transform Transforms this Region by the specified Matrix.
Public method Translate(Int32, Int32) Offsets the coordinates of this Region by the specified amount.
Public method Translate(Single, Single) Offsets the coordinates of this Region by the specified amount.
Public method Union(GraphicsPath) Updates this Region to the union of itself and the specified GraphicsPath.
Public method Union(Rectangle) Updates this Region to the union of itself and the specified Rectangle structure.
Public method Union(RectangleF) Updates this Region to the union of itself and the specified RectangleF structure.
Public method Union(Region) Updates this Region to the union of itself and the specified Region.
Public method Xor(GraphicsPath) Updates this Region to the union minus the intersection of itself with the specified GraphicsPath.
Public method Xor(Rectangle) Updates this Region to the union minus the intersection of itself with the specified Rectangle structure.
Public method Xor(RectangleF) Updates this Region to the union minus the intersection of itself with the specified RectangleF structure.
Public method Xor(Region) Updates this Region to the union minus the intersection of itself with the specified Region.
Top

A region is scalable because its coordinates are specified in world coordinates. On a drawing surface, however, its interior is dependent on the size and shape of the pixels representing it. An application can use regions to clip the output of drawing operations. These regions are called clipping regions. For more information on using regions for clipping, see How to: Use Clipping with a Region.

An application can also use regions in hit-testing operations, such as checking whether a point or a rectangle intersects a region. For more information on using regions for hit-testing, see How to: Use Hit Testing with a Region.

An application can fill a region by using the Graphics.FillRegion method and a Brush object.

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 example demonstrates how to use the Data from one RegionData object to set the Data for another RegionData.


private void DemonstrateRegionData2(PaintEventArgs e)
{

    //Create a simple region.
    Region region1 = new Region(new Rectangle(10, 10, 100, 100));

    // Extract the region data.
    System.Drawing.Drawing2D.RegionData region1Data = region1.GetRegionData();
    byte[] data1;
    data1 = region1Data.Data;

    // Create a second region.
    Region region2 = new Region();

    // Get the region data for the second region.
    System.Drawing.Drawing2D.RegionData region2Data = region2.GetRegionData();

    // Set the Data property for the second region to the Data from the first region.
    region2Data.Data = data1;

    // Construct a third region using the modified RegionData of the second region.
    Region region3 = new Region(region2Data);

    // Dispose of the first and second regions.
    region1.Dispose();
    region2.Dispose();

    // Call ExcludeClip passing in the third region.
    e.Graphics.ExcludeClip(region3);

    // Fill in the client rectangle.
    e.Graphics.FillRectangle(Brushes.Red, this.ClientRectangle);

    region3.Dispose();

}


.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ