Using Relative and Sequential Drawing

This topic provides examples that demonstrate how to draw a triangle first using relative drawing with a thin solid line, then using relative drawing and a wide line (illustrating curved corners) and finally 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.

Drawing a triangle using relative drawing (thin lines)

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)
...
      

Note : The sum of the three TPoint vectors used by the DrawLineBy() calls comes to (0,0) , thus creating a closed shape.

Drawing a triangle using relative drawing (thick lines)

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)
...
      

Drawing a triangle using sequential drawing between points

This topic provides an example that demonstrates how to 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)
...
      

Note : The final point drawn to is the same as the point originally moved to, thus creating a closed shape.