Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing form

Status
Not open for further replies.

ionutdinulescu

Programmer
Jun 11, 2002
59
GB
I want to print some controls on a form, but keeping their x,y positions.

How can I convert the Left/Top values to printer coordinates ?

Thanks
 
I don't understand what "print some controls on a form" means.

What are you trying to do?

Cheers
 
For example I have a label with top=5 left=15
I want to print its caption on a printer at the position
that coresponds to its left and top properties.

The problem is that I don't know what is the corespondence between the coordinates on the screen and those on the printer.
 
I take it that you are generating the print output via TPrinter.

You need to know the screen and printer canvas resolutions (not sure on how to determine these, but think these are typically 72dpi for screen and 600dpi for printer).

Then multiply the screen co-ordinates by (Printer Resolution/Screen Resolution) to get your printer co-ords.

Following code prints out Label1 when button clicked

procedure TForm1.Button1Click(Sender: TObject);
var
X, Y : Integer;
begin
X := Trunc(Form1.Label1.Left * 600/72);
Y := Trunc(Form1.Label1.Top * 600/72);
if PrintDialog1.Execute then
with printer do
begin
BeginDoc;
Printer.Canvas.TextOut(X,Y,Form1.Label1.Caption);
EndDoc;
end;
end;

Note: Printer co-ords are relative to the printers printable area. i.e. printing at 0,0 doesn't place the text right in the top left corner of the page - if you wanted the text relative to the page edges then you would have to factor for this.

Hope this helps,

Keith.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top