Name
Rectangle
Synopsis
This value type defines a rectangular region on a 2D surface using
integers. Unlike the Win32 RECT structure, the
Rectangle is defined in terms of the
X and Y coordinate of its
top-left point (also referred to as its Location), and its
Width and Height (also referred
to as its Size). These properties can be both read and modified. In
addition, you can read values for the Left,
Top, Right, and
Bottom independently, and there is a static
method, FromLTRB(), to allow you to construct a
Rectangle from these values in interop/legacy
situations.
As with Point, there is an equivalent
RectangleF structure for real coordinates, and a
set of members—Round(), Truncate(), and Ceiling()—to convert from
the real to the integer representation. Comparison operators are also
provided, along with an Empty field to allow you
to represent a null rectangle. There is no intrinsic performance
advantage in using the integer version, as the drawing methods are
mostly implemented in terms of the floating point structure anyway
(c.f. Point/PointF)
Methods are provided to test whether a rectangle Contains() a Point, and whether one rectangle
IntersectsWith() another for hit testing.
You can also manipulate the rectangle itself in various ways. There
is a static member, Union(), which returns the
minimum containing rectangle of two rectangles. Then there is the
member function, Intersect(), which modifies a
Rectangle such that it represents the area of intersection between itself and the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access