# Understanding Points Using Drawing2D in Microsoft C#

You are wondering what Drawing2D is in C#, basically it is namespace under **System.Drawing.Drawing2D **that provides advanced two-dimensional and vector graphics functionality.

So why **Points? **Points represent an integer x- and y-coordinates that defines a point in a two-dimensional plane. It assists in creating polygons like Triangles, quadrilaterals, pentagons, and hexagons.

Let’s say we want to create a triangle using, first we declare our points like;

`Point p0 = Point.Empty;`

Point p1 = Point.Empty;

Point p2 = Point.Empty;

First thing you need to have is a rectangle to draw the points in, create a rectangle like;

//set the location of your triangle withing your ClientRectangle otherwise leave at 0 so it can draw at far left of you form

int x,y = 0//width and height = 100

Rectangle rectangle = new Rectangle(x, y, 100, 100);

Then we initialize points with

`p0 = new Point(rectangle.Left + (rectangle.Width/2), rectangle.Top);`

p1 = new Point(rectangle.Left, rectangle.Bottom);

p2 = new Point(rectangle.Right, rectangle.Bottom);

Create Graphics to paint the points

Graphics graphics = this.CreateGraphics();

//use paint events if your want.

//make sure you include Smoothening Mode in your graphics for better looks like graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;SolidBrush solidbrush = new SolidBrush(Color.Black);

Pen pen = new Pen(solidbrush);

Paint the points like:

`graphics.DrawPolygon(pen, new Point[] { p0, p1, p2 });`

If you would wish to fill the you polygon use;

`graphics.FillPolygon(solidbrush, new Point[] { p0, p1, p2 });`

Result will be like

Here is the simplicity.

What if you just want to draw a V shape? This is how you hack it.

Change the location of your points to;

`p0 = new Point(rectangle.Left + (rectangle.Width / 2), rectangle.Bottom);`

p1 = new Point(rectangle.Left, rectangle.Top);

p2 = new Point(rectangle.Right, rectangle.Top);

So that **p0 **is on the bottom side then draw your polygon like;

`graphics.DrawPolygon(pen, new Point[] { p0, p2 , p0, p1});`

Result:

**NB: **Make sure you dispose your GDI Objects since they are unmanaged

`graphics.Dispose();`

pen.Dispose();

solidbrush.Dispose();

Source : https://github.com/k33ptoo/KeepToo_Points

Thank you for your time.

Check out my Youtube Channel : https://www.youtube.com/KeepToo