Page 1 of 1

TPrintPreview drawText problem

PostPosted: October 13th, 2017, 7:15 am
by john12345
Hello,
Recently, I have encountered the TPrintPreview problem with "canvas.drawText".
When I set the alignment to the right "DT_RIGTH" the text does not fit in the rectangle.

simple example:
preview.drawText (canvas.handle, 'test test test', -1, r, DT_RIGHT);

Please advise.
Piotr

Re: TPrintPreview drawText problem

PostPosted: October 13th, 2017, 8:16 am
by john12345
The problem exists when set mmLoMetric in units.

Re: TPrintPreview drawText problem

PostPosted: December 1st, 2017, 11:06 am
by dstu
Hallo, try this:
with PrintPreview.Canvas do begin
Brush.Color:=Base.FuellFarbe;
Brush.Style:=bsClear;
Font.Color:=Base.LinienFarbe;
Font.Size:=Base.FontSize;
Font.Name:=Base.FontName;
Font.Style:=Base.FontStyle;
rc:=Bounds(Base.X,Base.Y+Offset,Base.Width,Base.Height);
if Base.Align = DT_Right then begin
rc.Left:=rc.Right - TextWidth(s) - 10;
DrawText(Handle,PChar(String(s)),length(s),rc,DT_Left+DT_NOPREFIX);
end else DrawText(Handle,PChar(String(s)),length(s),rc,Base.Align+DT_NOPREFIX);
end;
best regards dstu