Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-2003, 10:15 AM
gveggi gveggi is offline
Junior Member
 
Join Date: Jun 2002
Posts: 13
Default 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
Reply With Quote
  #2  
Old 05-09-2003, 10:17 AM
gveggi gveggi is offline
Junior Member
 
Join Date: Jun 2002
Posts: 13
Default RE: I'sorry, must be right side

The alignment must be at right side.

Sorry
Reply With Quote
  #3  
Old 05-09-2003, 10:34 AM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default 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.

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;


Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
(No emails please unless explicitly requested!)
Reply With Quote
  #4  
Old 05-09-2003, 10:40 AM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: I'sorry, must be right side

Or, if you want to right-align on a decimal point, use:

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;


Please click accept if this helps

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:56 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.