Solved

Print form

Posted on 1998-07-16
9
244 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:sierra20
  • 4
  • 3
  • 2
9 Comments
 
LVL 1

Expert Comment

by:pjdb
Comment Utility
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
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
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
 
LVL 1

Expert Comment

by:pjdb
Comment Utility
Use div instead of / for the division, the parameters need to be integer
0
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
Of course, thanks.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:sierra20
Comment Utility
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
 

Author Comment

by:sierra20
Comment Utility
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
 
LVL 3

Expert Comment

by:Matvey
Comment Utility
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
 

Author Comment

by:sierra20
Comment Utility
Nice, its work now.
Just answers and thanks

0
 
LVL 3

Accepted Solution

by:
Matvey earned 50 total points
Comment Utility
OK, glad it works.
As I said - use PrintScale or StretchDraw.
Good luck, Matvey
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now