Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]


How to draw lines

The following example code demonstrates how to:

The code assumes a common pair of pre-defined points are used for each of the line drawing examples:

...
// set up a pair of points for drawing diagonal lines
TPoint startPoint(50,50);
TPoint endPoint(590,190);
...

[Top]


Drawing a line a single pixel wide

You can draw a thin line diagonally across the screen using DrawLine(). This illustrates how thin a single pixel width line is, and the visible stepping:

...
// draw a thin line from top left to bottom right 
gc.DrawLine(startPoint,endPoint);
...

Note

[Top]


Drawing a line 3 pixels wide

  1. Use SetPenSize() to increase the pen size to 3 pixels.

  2. Use DrawLine() to draw a wide line diagonally across the screen.

// Set up a "bold" size for the pen tip to (default is 1,1)
TSize penSizeBold(3,3);
...
// draw a line from top left to bottom right 
gc.SetPenSize(penSizeBold);
gc.DrawLine(startPoint,endPoint);
...

[Top]


Drawing a line 30 pixels wide

  1. Use SetPenWidth() to set the pen width to 30 pixels wide.

  2. Use DrawLine() to draw a 30 pixel wide line, (x dimension), diagonally across the screen.

// Set up a "fat" size for the pen tip
TSize penSizeFat(30,30);
...
// draw a rather wide line from top left to bottom right,
// illustrating rounded ends and their clipping
gc.SetPenWidth(penSizeFat);
gc.DrawLine(startPoint,endPoint);
...

Notes

[Top]


Drawing a dotted line

  1. Use SetPenStyle() to set the style of the pen to dotted.

  2. Use DrawLine() to draw a thin dotted line diagonally across the screen.

...
// draw a dotted line from top left to bottom right 
gc.SetPenStyle(CGraphicsContext::EDottedPen);
gc.DrawLine(startPoint,endPoint);
...

Note

[Top]


Drawing a dot-dashed line

  1. Use SetPenStyle() to set the style of the pen to dot-dashed.

  2. Use DrawLine() to draw a thin dot-dashed line diagonally across the screen.

...
// draw a dot dash line from top left to bottom right 
gc.SetPenStyle(CGraphicsContext::EDotDashPen);
gc.DrawLine(startPoint,endPoint);
...