"Mark L. Tiede" <mti...@mjwcorp.com> wrote in message news:393CF8CD.893BC345@mjwcorp.com...
Quote
> Is there a way to have a Panel Print itself? Or get it to draw itself to a
> Canvas or something? I have all my objects contained in a TPanel for clipping
> reasons. If I could print the Panel, that would help.
Normally I'd point you to my "Printing" page and tell you to check out a link
there, but Deja has messed up most of its older links, so I'll just repost this:
================================================================
From: "Earl F. Glynn" <EarlGl...@att.net>
Subject: Re: Printing a panel
Date: 03 Jun 1999 00:00:00 GMT
Message-ID: <7j6seo$lsn5@forums.borland.com>
References: <7j6gur$lei18@forums.borland.com>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Organization: Another Netscape Collabra Server User
X-MSMail-Priority: Normal
Newsgroups: borland.public.delphi.graphics
Quote
Bill Talbert <btalb...@marathonoil.com> wrote in message
news:7j6gur$lei18@forums.borland.com...
Quote
> Ok, I got you this far, hang in there. This is a tough one, at least for
> me.
> I want to print out the contents I have placed on a panel. I have placed
> several images and assorted graphic controls on the panel. Now I want to
> print it out. My problem is the panel does not have a canvas property.
> Some how I should be able to manipulate the "graphics" on the panel. What I
> thought might work is to do a screen capture of the panel area, but I am not
> sure what the function calls are.
> Does anybody have any ideas. I want to be able to scale the image and print
> it to a specific part of the page
The Form has a canvas. You can create a new bitmap the same size as your panel
and then use CopyRect to copy the Panel and its content from the Form to this
in-memory bitmap. Then you can print the in-memory bitmap. Here's an example:
procedure TFormPrintWindows.ButtonPrintPanelClick(Sender: TObject);
var
Bitmap : TBitmap;
FromLeft : INTEGER;
FromTop : INTEGER;
PrintedWidth : INTEGER;
PrintedHeight: INTEGER;
begin
Printer.BeginDoc;
TRY
Bitmap := TBitmap.Create;
TRY
Bitmap.Width := Panel1.Width;
Bitmap.Height := Panel1.Height;
Bitmap.PixelFormat := pf24bit; // avoid palettes
// Copy the Panel area from the Form into a separate Bitmap
Bitmap.Canvas.CopyRect(Rect(0,0, Bitmap.Width,Bitmap.Height),
FormPrintWindows.Canvas,
Rect(Panel1.Left, Panel1.Top,
Panel1.Left + Panel1.Width-1,
Panel1.Top + Panel1.Height-1) );
// Assumes 10% left, right and top margin
// Assumes bitmap aspect ratio > ~0.75 for portrait mode
PrintedWidth := MulDiv(Printer.PageWidth, 80,100); // 80%
PrintedHeight := MulDiv(PrintedWidth, Bitmap.Height, Bitmap.Width);
FromLeft := MulDiv(Printer.PageWidth, 10,100); // 10%
FromTop := MulDiv(Printer.PageHeight,10,100); // 10%
PrintBitmap(Printer.Canvas,
Rect(FromLeft, FromTop,
FromLeft + PrintedWidth,
FromTop + PrintedHeight),
Bitmap);
FINALLY
Bitmap.Free
END;
FINALLY
Printer.EndDoc
END
end;
--
efg
Earl F. Glynn E-mail: EarlGl...@att.net
Overland Park, KS USA
efg's Computer Lab: http://www.efg2.com/Lab