unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls ,Clipbrd, Grids, jpeg, ComCtrls,Printers;
type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
Label1: TLabel;
Image2: TImage;
Image3: TImage;
Image4: TImage;
CheckBox1: TCheckBox;
RadioButton1: TRadioButton;
StatusBar1: TStatusBar;
DisplayButton: TButton;
ExitButton: TButton;
PrintButton: TButton;
Button1: TButton;
Button2: TButton;
procedure DisplayButtonClick(Sender: TObject);
procedure ExitButtonClick(Sender: TObject);
procedure PrintButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function PanelImage(aForm:TForm): TBitmap;
var
Ofs: Integer;
begin
Result := TBitmap.Create;
try
Result.Width := aForm.ClientWidth;
Result.Height := aForm.ClientHeight;
Result.Canvas.Brush :=aForm.Brush;
Result.Canvas.FillRect(aForm.ClientRect);
Result.Canvas.Lock;
try
if GetWindowLong(aForm.Handle, GWL_STYLE) and WS_BORDER <> 0 then
Ofs := -1 //do
n't Panel form border
else
Ofs := 0;
// There is no border
aForm.PaintTo(Result.Canvas.Handle, Ofs, Ofs);
finally
Result.Canvas.Unlock;
end;
except
Result.Free;
raise;
end;
end;
procedure TForm1.DisplayButtonClick(Sender: TObject);
var
FormImage: TBitmap;
begin
FormImage := PanelImage(Form1);
try
//Clipboard.Assign(FormImage);
Image2.Picture.Assign(FormImage);
finally
FormImage.Free;
end;
end;
procedure TForm1.ExitButtonClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.PrintButtonClick(Sender: TObject);
var
FormImage: TBitmap;
begin
FormImage := PanelImage(Form1);
Printer.begin
Doc;
Printer.Canvas.Draw(20,20,FormImage);
Printer.EndDoc;
end;
end.
本来Form有一个函数是用来打印上面的图形的,我记不清了,有一位朋友问如何打印Panel上的东西,我按照Delphi提供的那个函数写了一个,这个程序可以打印Form上的内容,如果保留Clipboard.Assign(FormImage);这个时候粘贴板里有Form的图形,你可以试一试