This topic provides examples that demonstrate how to draw lines of different widths and styles.
The examples assume common start and end points have been defined as follows:
... // set up a pair of points for drawing diagonal lines TPoint startPoint(50,50); TPoint endPoint(590,190); ...
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: The line width is a single pixel by default.
Use SetPenSize()
to increase the pen size to three pixels.
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); ...
Use SetPenWidth()
to set the pen width to thirty pixels wide.
Use DrawLine()
to draw a thirty 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
Use SetPenStyle()
to set the style of the pen to dotted.
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: The pen style remains in effect until changed by another call to SetPenStyle()
or the graphics context is reset to its default settings.
Use SetPenStyle()
to set the style of the pen to dot-dashed.
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); ...