这个例子是把Panel中的所有内容作为Bitmap拷到剪贴版,另外可以用Image显示
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls ,Clipbrd, Grids;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Image1: TImage;
Label1: TLabel;
Button2: TButton;
Image2: TImage;
DrawGrid1: TDrawGrid;
Image3: TImage;
Image4: TImage;
procedure Button1Click(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 // Don't draw 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.Button1Click(Sender: TObject);
var
FormImage: TBitmap;
begin
FormImage := PanelImage(Panel1);
try
Clipboard.Assign(FormImage);
Image2.Picture.Assign(Clipboard);
finally
FormImage.Free;
end;
end;
end.