这里有一些代码,你试一试
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;
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(aPanel:TPanel): TBitmap;
var
Ofs: Integer;
begin
Result := TBitmap.Create;
try
Result.Width := aPanel.ClientWidth;
Result.Height := aPanel.ClientHeight;
Result.Canvas.Brush :=aPanel.Brush;
Result.Canvas.FillRect(aPanel.ClientRect);
Result.Canvas.Lock;
try
if GetWindowLong(aPanel.Handle, GWL_STYLE) and WS_BORDER <> 0 then
Ofs := -1 //do
n't Panel form border
else
Ofs := 0;
// There is no border
aPanel.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(Panel1);
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(Panel1);
Printer.begin
Doc;
Printer.Canvas.Draw(20,20,FormImage);
Printer.EndDoc;
end;
end.