In the following example code a triangle is drawn:
using relative drawing with a thin solid line
using relative drawing a wide line, illustrating curved corners
using sequential drawing between points, with a dot dash line, illustrating line pattern continuation
Note that there is a third way to draw a triangle, using
DrawPolygon()
. This must be to used to draw a filled
triangle.
You can draw a triangle of thin lines, using relative drawing,
MoveTo()
and DrawLineBy()
.
...
// draw a triangle by relative drawing
gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
gc.DrawLineBy(TPoint(205,100)); // drawing position (505,150)
gc.DrawLineBy(TPoint(-410,0)); // drawing position (95,150)
gc.DrawLineBy(TPoint(205,-100)); // drawing position (300,50)
...
The sum of the three TPoint
vectors used by the
DrawLineBy()
calls comes to (0,0)
, thus creating a
closed shape.
You can draw a triangle of thick lines, using relative drawing,
MoveTo()
and DrawLineBy()
.
...
// draw a triangle, by relative drawing
// illustrating rounded ends at corners when using very wide lines
gc.SetPenWidth(penSizeFat);
gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
gc.DrawLineBy(TPoint(205,100)); // drawing position (505,150)
gc.DrawLineBy(TPoint(-410,0)); // drawing position (95,150)
gc.DrawLineBy(TPoint(205,-100)); // drawing position (300,50)
...
You can draw a triangle of dot dash lines, using sequential drawing
between points, DrawLineTo()
.
...
// draw a triangle by sequential drawing between specified points,
// using dot-dash line style, illustrating line pattern continuation
gc.SetPenStyle(CGraphicsContext::EDotDashPen);
gc.MoveTo(TPoint(300,50)); // drawing position (300,50)
gc.DrawLineTo(TPoint(505,150)); // drawing position (505,150)
gc.DrawLineTo(TPoint(95,150)); // drawing position (95,150)
gc.DrawLineTo(TPoint(300,50)); // drawing position (300,50)
...
The final point drawn to is the same as the point originally moved to, thus creating a closed shape.