• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

using tcustomform.print

This is very sad. All I want to do is print the form out.
help says that
print;
will do it by getting a bmp image of the form and feeding it to the printer.
Fine. That's what I want. A nice simple print of the form.
But blank paper keeps coming out. (I've checked the ink <g>)
My form has panels and captions and a bmp background, but simply
putting a label on and using 'print ;' doesn't work.
I've tried 'form1.print ;' but still the same result.
What am I doing wrong?

what is the easiest way to print my form. I thought this was it!
 
0
chriswood
Asked:
chriswood
1 Solution
 
IndefreiCommented:
var
SRect,DRect: TRect; // Source Destination Rectangle
Tmp : TPicture;
begin
// Initialize the rectangles
Tmp.Bitmap.Canvas.copyrect( dRect, Form1.Canvas,SRect);
assign it to image1
Print the Bitmap with
e.g.
Printer.Canvas.StretchDraw(dRect, Image1.Picture.Graphic);
regards
Indi
0
 
IndefreiCommented:
Chriswood,
i think you have to use after begin
Tmp :=TPicture.Create;
and in the end
tmp.free;

>>assign it to image1
Image1.Picture.Assign(Tmp);
and use
Printer.BeginDoc;
Printer.EndDoc;
for printing
Indi
0
 
DrDelphiCommented:
Are you sure that you're getting nothing? You might be getting a very small image printed on the page. The Print method does no scaling at all, it just takes the form's image and throws it at the printer. It might be huge, it might be a postage stamp.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sburckCommented:
I tried this, with a button on a blank form, and it printed out fine.  Looking in the help, though, I see a direction.  The print method uses the GetFormImage method.  You can use the GetFormImage method and put the bitmap to a file or the clipboard, and see if DrDelphi is right (scaling problem), or something else (printer driver).

0
 
sburckCommented:
On second thought, looking more closely at the source of TCustomForm.Print, if DrDelphi is right, set the PrintScale method to poPrintToFit, and that will either fix your problem or eliminate one more idea.
0
 
chriswoodAuthor Commented:
thanks to you 3. Actually sburck's comment helped me solve this. He confirmed that it should simply work! I tried with a different printer and it worked first time. I don't know what's wrong with my Hp laserjet 4000 but it was the printer not my programming...

But I would have gone round in circles without that... thanks again,
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now