Graphics.DrawRectangle Method (Pen, Int32, Int32, Int32, Int32)

Draws a rectangle specified by a coordinate pair, a width, and a height.

Namespace: Aurigma.GraphicsMill.Drawing
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

C#
public void DrawRectangle(
	Pen pen,
	int x,
	int y,
	int width,
	int height
)

Parameters

pen

Type: Aurigma.GraphicsMill.Drawing.Pen

A Pen that determines the color, width, and style of the rectangle.
x

Type: System.Int32

The x-coordinate of the upper-left corner of the rectangle to draw.
y

Type: System.Int32

The y-coordinate of the upper-left corner of the rectangle to draw.
width

Type: System.Int32

The width of the rectangle to draw.
height

Type: System.Int32

The height of the rectangle to draw.

Remarks

To fill a rectangle, use FillRectangle(Brush, Int32, Int32, Int32, Int32) method.

Examples

C#
using (var bitmap = new Bitmap(185, 145, PixelFormat.Format24bppRgb, RgbColor.White))
{
    using (Graphics graphics = bitmap.GetGraphics())
    {
        //Draw filled and outlined rectangle
        var pen = new Pen(RgbColor.Red, 3);
        var brush = new SolidBrush(RgbColor.Lavender);
        graphics.FillRectangle(brush, 10, 10, 100, 60);
        graphics.DrawRectangle(pen, 10, 10, 100, 60);

        //Draw filled but non-outlined ellipse
        brush.Color = RgbColor.Yellow;
        graphics.FillEllipse(brush, 60, 40, 100, 80);

        //Draw outlined but non-filled polygon 
        pen.Color = RgbColor.Green;
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
        pen.Width = 2;
        System.Drawing.Point[] points = { 
            new System.Drawing.Point(20, 30), new System.Drawing.Point(50, 2), 
            new System.Drawing.Point(180, 30), new System.Drawing.Point(80, 140)
        };
        graphics.DrawPolygon(pen, points);
    }
    bitmap.Save(@"Images\Output\shapesGDI.png");
}

See Also

Reference