whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

43 Visitors Online


 
.. create your own TPen Style?
Autor: Benjamin van Eck
[ Print tip ]  

Tip Rating (27):  
     


{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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}


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners