Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   Printing aligned (http://www.delphipages.com/forum/showthread.php?t=89340)

gveggi 05-09-2003 11:15 AM

Printing aligned
 
I have to print aligned at left side via Printer.Canvas

Report example:
Name Count
Green 10
Total 150
Gray 14
Total 25.000
Red 8
Total 2200

I have to print like this:
Name Count
Green 10
Total 150
Gray 14
Total 25.000
Red 8
Total 2200

Thanks

gveggi 05-09-2003 11:17 AM

RE: I'sorry, must be right side
 
The alignment must be at right side.

Sorry

simes 05-09-2003 11:34 AM

RE: I'sorry, must be right side
 
Here's an example that paints to the Form canvas, but you can just replace that with the printer canvas.
<tt>
procedure TForm1.FormPaint(Sender: TObject);
procedure RightAlign(const str: string; const x, y: integer);
begin
Canvas.TextOut(x - Canvas.TextWidth(str), y, str);
end;

const
col1 = 100;
col2 = 150;
var
y, h: integer;
begin
Canvas.Brush.Style := bsClear;
h := round(Canvas.TextHeight('Hg') * 1.2);
y := 20;
RightAlign('Green', col1, y); RightAlign('10', col2, y);
inc(y, h);
RightAlign('Total', col1, y); Rightalign('150', col2, y);
inc(y, h);
RightAlign('Gray', col1, y); Rightalign('14', col2, y);
inc(y, h);
RightAlign('Total', col1, y); Rightalign('25.000', col2, y);
inc(y, h);
RightAlign('Red', col1, y); Rightalign('8', col2, y);
inc(y, h);
RightAlign('Total', col1, y); Rightalign('2200', col2, y);
end;
</tt>

<cr>Please click accept if this helps</cr>

Simon
SadMan Software
http://www.simes.clara.co.uk
(No emails please unless explicitly requested!)

simes 05-09-2003 11:40 AM

RE: I'sorry, must be right side
 
Or, if you want to right-align on a decimal point, use:
<tt>
procedure RightAlign(const str: string; const x, y: integer);
var
p,w: integer;
begin
p := Pos('.', str);
if p > 0 then
w := Canvas.TextWidth(Copy(str, 1, p - 1))
else
w := Canvas.TextWidth(str);
Canvas.TextOut(x - w, y, str);
end;
</tt>

<cr>Please click accept if this helps</cr>

Simon
SadMan Software
http://www.simes.clara.co.uk
(No emails please unless explicitly requested!)


All times are GMT. The time now is 07:02 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.