Understanding Points Using Drawing2D in Microsoft C#

Point p0 = Point.Empty;
Point p1 = Point.Empty;
Point p2 = Point.Empty;
//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);
p0 = new Point(rectangle.Left + (rectangle.Width/2), rectangle.Top);
p1 = new Point(rectangle.Left, rectangle.Bottom);
p2 = new Point(rectangle.Right, rectangle.Bottom);
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);
graphics.DrawPolygon(pen, new Point[] { p0, p1, p2 });
graphics.FillPolygon(solidbrush, new Point[] { p0, p1, p2 });
p0 = new Point(rectangle.Left + (rectangle.Width / 2), rectangle.Bottom);
p1 = new Point(rectangle.Left, rectangle.Top);
p2 = new Point(rectangle.Right, rectangle.Top);
graphics.DrawPolygon(pen, new Point[] { p0, p2 , p0, p1});
graphics.Dispose();
pen.Dispose();
solidbrush.Dispose();

--

--

I'm a computer user who writes​ code, UI-UX & Information Security Enthusiast.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amos Chepchieng

Amos Chepchieng

I'm a computer user who writes​ code, UI-UX & Information Security Enthusiast.