You can draw a homogeneous triangle, then rotate it and scale it using the Matrix transform to fit inside the rectangle, but to be honest, I think there is more work than just defining each point.
private void DrawTriangle(Graphics g, Rectangle rect, Direction direction) { int halfWidth = rect.Width / 2; int halfHeight = rect.Height / 2; Point p0 = Point.Empty; Point p1 = Point.Empty; Point p2 = Point.Empty; switch (direction) { case Direction.Up: p0 = new Point(rect.Left + halfWidth, rect.Top); p1 = new Point(rect.Left, rect.Bottom); p2 = new Point(rect.Right, rect.Bottom); break; case Direction.Down: p0 = new Point(rect.Left + halfWidth, rect.Bottom); p1 = new Point(rect.Left, rect.Top); p2 = new Point(rect.Right, rect.Top); break; case Direction.Left: p0 = new Point(rect.Left, rect.Top + halfHeight); p1 = new Point(rect.Right, rect.Top); p2 = new Point(rect.Right, rect.Bottom); break; case Direction.Right: p0 = new Point(rect.Right, rect.Top + halfHeight); p1 = new Point(rect.Left, rect.Bottom); p2 = new Point(rect.Left, rect.Top); break; } g.FillPolygon(Brushes.Black, new Point[] { p0, p1, p2 }); }
source share