[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Stores a set of four integers that represent the location and size of a rectangle
<SerializableAttribute> _ <ComVisibleAttribute(True)> _ <TypeConverterAttribute(GetType(RectangleConverter))> _ Public Structure Rectangle
[SerializableAttribute] [ComVisibleAttribute(true)] [TypeConverterAttribute(typeof(RectangleConverter))] public struct Rectangle
[SerializableAttribute] [ComVisibleAttribute(true)] [TypeConverterAttribute(typeof(RectangleConverter))] public value class Rectangle
[<Sealed>] [<SerializableAttribute>] [<ComVisibleAttribute(true)>] [<TypeConverterAttribute(typeof(RectangleConverter))>] type Rectangle = struct end
The Rectangle type exposes the following members.
A rectangle is defined by its Width, Height, and upper-left corner represented by the Location property.
To draw rectangles, you need a Graphics object and a Pen object. The Graphics object provides the DrawRectangle method, and the Pen object stores features of the line, such as color and width. The units the rectangle is drawn in is determined by the PageUnit and PageScale properties of the graphics object used for drawing. The default unit is pixels.
To draw a Rectangle filled with color, you need a Graphics object and an object derived from Brush such as SolidBrush or LinearGradientBrush. The Graphics object provides the FillRectangle method and the Brush object provides the color and fill information.
For more advanced shapes, use a Region object.
The following example draws a rectangle with its upper-left corner at (10, 10). The rectangle has a width of 100 and a height of 50. The second argument passed to the Pen constructor indicates that the pen width is 5 pixels.
When the rectangle is drawn, the pen is centered on the rectangle's boundary. Because the pen width is 5, the sides of the rectangle are drawn 5 pixels wide, such that 1 pixel is drawn on the boundary itself, 2 pixels are drawn on the inside, and 2 pixels are drawn on the outside. For more details on pen alignment, see How to: Set Pen Width and Alignment.
The following illustration shows the resulting rectangle. The dotted lines show where the rectangle would have been drawn if the pen width had been one pixel. The enlarged view of the upper-left corner of the rectangle shows that the thick black lines are centered on those dotted lines.
This example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler.
Dim blackPen As New Pen(Color.FromArgb(255, 0, 0, 0), 5) e.Graphics.DrawRectangle(blackPen, 10, 10, 100, 50)
Pen blackPen = new Pen(Color.FromArgb(255, 0, 0, 0), 5); e.Graphics.DrawRectangle(blackPen, 10, 10, 100, 50);
Windows 8 Consumer Preview, Windows Server 8 Beta, Windows 7, Windows Server 2008 SP2, 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.