Bewerken

Share via


Region Class

Definition

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

public ref class Region sealed : MarshalByRefObject, IDisposable
public sealed class Region : MarshalByRefObject, IDisposable
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class Region : MarshalByRefObject, IDisposable
type Region = class
    inherit MarshalByRefObject
    interface IDisposable
[<System.Runtime.InteropServices.ComVisible(false)>]
type Region = class
    inherit MarshalByRefObject
    interface IDisposable
Public NotInheritable Class Region
Inherits MarshalByRefObject
Implements IDisposable
Inheritance
Attributes
Implements

Examples

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.
      System::Drawing::Region^ region1 = gcnew System::Drawing::Region( Rectangle(10,10,100,100) );

      // Extract the region data.
      System::Drawing::Drawing2D::RegionData^ region1Data = region1->GetRegionData();
      array<Byte>^data1;
      data1 = region1Data->Data;

      // Create a second region.
      System::Drawing::Region^ region2 = gcnew System::Drawing::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.
      System::Drawing::Region^ region3 = gcnew System::Drawing::Region( region2Data );

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

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

      // Fill in the client rectangle.
      e->Graphics->FillRectangle( Brushes::Red, this->ClientRectangle );
      delete region3;
   }
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();
}
Private Sub DemonstrateRegionData2(ByVal e As PaintEventArgs)

    'Create a simple region.
    Dim region1 As New Region(New Rectangle(10, 10, 100, 100))

    ' Extract the region data.
    Dim region1Data As System.Drawing.Drawing2D.RegionData = region1.GetRegionData
    Dim data1() As Byte
    data1 = region1Data.Data

    ' Create a second region.
    Dim region2 As New Region

    ' Get the region data for the second region.
    Dim region2Data As System.Drawing.Drawing2D.RegionData = 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.
    Dim region3 As 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, Me.ClientRectangle)

    region3.Dispose()

End Sub

Remarks

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.

Note

In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.

Constructors

Region()

Initializes a new Region.

Region(GraphicsPath)

Initializes a new Region with the specified GraphicsPath.

Region(Rectangle)

Initializes a new Region from the specified Rectangle structure.

Region(RectangleF)

Initializes a new Region from the specified RectangleF structure.

Region(RegionData)

Initializes a new Region from the specified data.

Methods

Clone()

Creates an exact copy of this Region.

Complement(GraphicsPath)

Updates this Region to contain the portion of the specified GraphicsPath that does not intersect with this Region.

Complement(Rectangle)

Updates this Region to contain the portion of the specified Rectangle structure that does not intersect with this Region.

Complement(RectangleF)

Updates this Region to contain the portion of the specified RectangleF structure that does not intersect with this Region.

Complement(Region)

Updates this Region to contain the portion of the specified Region that does not intersect with this Region.

CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose()

Releases all resources used by this Region.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Equals(Region, Graphics)

Tests whether the specified Region is identical to this Region on the specified drawing surface.

Exclude(GraphicsPath)

Updates this Region to contain only the portion of its interior that does not intersect with the specified GraphicsPath.

Exclude(Rectangle)

Updates this Region to contain only the portion of its interior that does not intersect with the specified Rectangle structure.

Exclude(RectangleF)

Updates this Region to contain only the portion of its interior that does not intersect with the specified RectangleF structure.

Exclude(Region)

Updates this Region to contain only the portion of its interior that does not intersect with the specified Region.

Finalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

FromHrgn(IntPtr)

Initializes a new Region from a handle to the specified existing GDI region.

GetBounds(Graphics)

Gets a RectangleF structure that represents a rectangle that bounds this Region on the drawing surface of a Graphics object.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetHrgn(Graphics)

Returns a Windows handle to this Region in the specified graphics context.

GetLifetimeService()
Obsolete.

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetRegionData()

Returns a RegionData that represents the information that describes this Region.

GetRegionScans(Matrix)

Returns an array of RectangleF structures that approximate this Region after the specified matrix transformation is applied.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()
Obsolete.

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
Intersect(GraphicsPath)

Updates this Region to the intersection of itself with the specified GraphicsPath.

Intersect(Rectangle)

Updates this Region to the intersection of itself with the specified Rectangle structure.

Intersect(RectangleF)

Updates this Region to the intersection of itself with the specified RectangleF structure.

Intersect(Region)

Updates this Region to the intersection of itself with the specified Region.

IsEmpty(Graphics)

Tests whether this Region has an empty interior on the specified drawing surface.

IsInfinite(Graphics)

Tests whether this Region has an infinite interior on the specified drawing surface.

IsVisible(Int32, Int32, Graphics)

Tests whether the specified point is contained within this Region object when drawn using the specified Graphics object.

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.

IsVisible(Int32, Int32, Int32, Int32)

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

IsVisible(Point, Graphics)

Tests whether the specified Point structure is contained within this Region when drawn using the specified Graphics.

IsVisible(Point)

Tests whether the specified Point structure is contained within this Region.

IsVisible(PointF, Graphics)

Tests whether the specified PointF structure is contained within this Region when drawn using the specified Graphics.

IsVisible(PointF)

Tests whether the specified PointF structure is contained within this Region.

IsVisible(Rectangle, Graphics)

Tests whether any portion of the specified Rectangle structure is contained within this Region when drawn using the specified Graphics.

IsVisible(Rectangle)

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

IsVisible(RectangleF, Graphics)

Tests whether any portion of the specified RectangleF structure is contained within this Region when drawn using the specified Graphics.

IsVisible(RectangleF)

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

IsVisible(Single, Single, Graphics)

Tests whether the specified point is contained within this Region when drawn using the specified Graphics.

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.

IsVisible(Single, Single, Single, Single)

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

IsVisible(Single, Single)

Tests whether the specified point is contained within this Region.

MakeEmpty()

Initializes this Region to an empty interior.

MakeInfinite()

Initializes this Region object to an infinite interior.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
ReleaseHrgn(IntPtr)

Releases the handle of the Region.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
Transform(Matrix)

Transforms this Region by the specified Matrix.

Translate(Int32, Int32)

Offsets the coordinates of this Region by the specified amount.

Translate(Single, Single)

Offsets the coordinates of this Region by the specified amount.

Union(GraphicsPath)

Updates this Region to the union of itself and the specified GraphicsPath.

Union(Rectangle)

Updates this Region to the union of itself and the specified Rectangle structure.

Union(RectangleF)

Updates this Region to the union of itself and the specified RectangleF structure.

Union(Region)

Updates this Region to the union of itself and the specified Region.

Xor(GraphicsPath)

Updates this Region to the union minus the intersection of itself with the specified GraphicsPath.

Xor(Rectangle)

Updates this Region to the union minus the intersection of itself with the specified Rectangle structure.

Xor(RectangleF)

Updates this Region to the union minus the intersection of itself with the specified RectangleF structure.

Xor(Region)

Updates this Region to the union minus the intersection of itself with the specified Region.

Applies to

See also