Print form

Hi

   I have to print a form and center it on the page. When i print the form (with form1.print), its always print it in the left top corner of the paper and i didnt want that. How can i center it ?
Id like to have some example.

Thanks
sierra20Asked:
Who is Participating?
 
MatveyCommented:
OK, glad it works.
As I said - use PrintScale or StretchDraw.
Good luck, Matvey
0
 
pjdbCommented:
Var
  DestRect:TRect;
Begin
 Printer.BeginDoc;
 DestRect.Left:=Printer.Canvas.ClipRect.Left + (Printer.Canvas.ClipRect.Right - Form1.Width) div 2;
 DestRect.Right:=DestRect.Left + Form1.Width;
 DestRect.Top:=Printer.Canvas.ClipRect.Top + (Printer.Canvas.ClipRect.Bottom - Form1.Height) div 2;
 DestRect.Bottom:=DestRect.Top + Form1.Height;
 Printer.Canvas.CopyRect( DestRect, Form1.Canvas, Form1.ClientRect);
 Printer.EndDoc;
end;
0
 
MatveyCommented:
Here is a code that draws the form image on the Printer.Canvas in the center by calculating coordinates:

Printer.BeginDoc;
Printer.Canvas.Draw(Printer.PageWidth/2 - Form1.GetFormImage.Width/2, Printer.PageHeight/2 - Form1.GetFormImage.Height/2, Form1.GetFormImage);
Printer.EndDoc

Cheers, Matvey
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
pjdbCommented:
Use div instead of / for the division, the parameters need to be integer
0
 
MatveyCommented:
Of course, thanks.
0
 
sierra20Author Commented:
Ok, now im able to center the form but when i print it, it didnt print on all the paper, it just print the form really small. How can i print on all the paper??
0
 
sierra20Author Commented:
Ok, now im able to center the form but when i print it, it didnt print on all the paper, it just print the form really small. How can i print on all the paper??
0
 
MatveyCommented:
It's even easier - set form.PrintScale := poPrintToFit, and call form.print, or center it and print.
If you want your form to cover all the page, than you have to stretch it. Use Printer.Canvas.StretchDraw for this.
0
 
sierra20Author Commented:
Nice, its work now.
Just answers and thanks

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.