Name

Region

Synopsis

This class is used to define an arbitrary region on a 2D surface.

This is a resource-based entity (unlike the Rectangle and Point value types), and therefore requires careful lifetime management. You should Dispose() the object when you are finished with it to release the resources back to the system.

At its simplest, you can construct a Region from a Rectangle or RectangleF. More complex regions can be constructed from a System.Drawing.Drawing2D.GraphicsPath. For interop with the Win32 HRGN, you can use GetHrgn() and FromHrgn().

You can then manipulate the region in a variety of ways, including logical operations with another Region, System.Drawing.Drawing2D.GraphicsPath, or Rectangle / RectangleF. It can also be made to represent no area at all with the MakeEmpty() method, or the whole of the infinite plane with MakeInfinite(). You can create the Complement() (the area of the supplied object that does not intersect with the Region), Intersect() two regions, create Union() of two regions (the combined areas of both), and Xor() two regions (which is equivalent to the Union( )Intersect()).

You can also provide a Matrix and Transform() the region, or simply Translate() it. This is not an ambient transformation like the ones provided for a Pen or Graphics surface—it actually manipulates the underlying System.Drawing.Drawing2D.RegionData.

There is an Equals() method, which determines whether two Region objects would be equivalent on a given Graphics surface, and you can ...

Get .NET Windows Forms in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.