I need draw some lines on a canvas, however I need use a custom style, no standart style as solid, dot, ...
For example I need draw a line as "__ . __ . _" or " . _ . _ . _ . _". All my line are a mix of dash and dot and I need set also dash lenght and dash, dot width.
I don't want use GDI+ or other external library...
Is there a simple way to do it?
You can do this with plain GDI:
procedure TForm1.FormPaint(Sender: TObject);
const
pattern: array[0..3] of cardinal = (10, 1, 1, 1);
var
lb: TLogBrush;
pen, oldpen: HPEN;
begin
lb.lbStyle := BS_SOLID;
lb.lbColor := RGB(255, 0, 0);
pen := ExtCreatePen(PS_COSMETIC or PS_USERSTYLE, 1, lb, length(pattern), @pattern);
if pen <> 0 then
try
oldpen := SelectObject(Canvas.Handle, pen);
Canvas.MoveTo(0, 0);
Canvas.LineTo(ClientWidth, ClientHeight);
SelectObject(Canvas.Handle, oldpen);
finally
DeleteObject(pen);
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With