Mega Code Archive

 
Categories / Delphi / Graphic
 

Create your own TPen Style

Title: create your own TPen Style? {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ I had to draw a dotted line on the printer canvas, but when I used the standard penstyle psDot in Delphi the dots where 1 centimeter long. So I had to figure out how to draw smaller dots on the printer canvas. The Windows API provides a funtion: ExtCreatePen(...) to create your own penstyle. So now, just specify how long the dots should be and the white space between the dots and voila! you created your own style. This is how it works: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++} { First: define your penstyle by creating a array of DWord. This array can be as long as you want to. Just remember to have an even count of objects of DWord in the array. Mine this on a printer with 600 dpi: } kleefPenStyle: array[1..2] of DWORD = (10, 10); {I only had to define the first length of the dot and the first white space, but add more DWord objects as you like.} { Secondly: define the look of you Pen, by setting the brush. I have created a variable: } logBrush: TLogBrush. //Set the brush in your code: logBrush.lbStyle := BS_SOLID; logBrush.lbColor := Canvas.Pen.Color; { Finally: make your penstyle known to the Pen: } Canvas.Pen.Handle := ExtCreatePen(PS_GEOMETRIC or PS_USERSTYLE, Canvas.Pen.Width, logBrush, Length(kleefPenStyle), @kleefPenStyle); {By giving PS_USERSTYLE with the dwPenStyle parameter you let Windows know you've created you own penstyle. The rest of the parameters must be clear to you. Benjamin}