Link to home
Start Free TrialLog in
Avatar of chriswood
chriswood

asked on

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!
 
Avatar of Indefrei
Indefrei

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
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
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.
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).

ASKER CERTIFIED SOLUTION
Avatar of sburck
sburck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chriswood

ASKER

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,