Preparatory work:
Place a tpanel on the form; Put a timage on the Tpanel; Another three buttons are required.
This example effect chart:
First edition code:
Unit Unit1; Interface uses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Extctrl
S
Type TFORM1 = Class (Tform) Button1:tbutton;
Button2:tbutton;
Button3:tbutton;
Panel1:tpanel;
Image1:timage;
Procedure Button1Click (Sender:tobject);
Procedure Button2click (Sender:tobject);
Procedure Button3click (Sender:tobject);
End
var Form1:tform1;
Implementation {$R *.DFM} uses CLIPBRD;
Procedure Tform1.button1click (Sender:tobject);
Begin Image1.left: = 0;
Image1.top: = 0;
Panel1.autosize: = True;
Image1.autosize: = True;
Image1.Picture.LoadFromFile (' c:\temp\test.bmp '); TButton (Sender).
Caption: = ' import ';
End
Procedure Tform1.button2click (Sender:tobject); Begin Clipboard.assign (image1.picture);
{Put the picture in the Image1 into the clipboard}
{Now can be pasted in the image software, you can try it with a Windows drawing board} TButton (Sender).
Caption: = ' copy ';
End
Procedure Tform1.button3click (Sender:tobject); var Bit:tbitmap; {Prepare to use aTbitmap from the Clipboard to end the picture} X,y:integer;
Begin bit: = Tbitmap.create; Bit. Assign (Clipboard); {Get from the Clipboard} x: = Panel1.width + panel1.left * 2;
{X,y is ready to paste position on the form} y: = Panel1.top; Canvas.draw (x, y, bit); {Paste is to draw out the bit.}
Free; TButton (Sender).
Caption: = ' paste ';
End End.
But now the program still has a loophole: if there is nothing in the Clipboard, what to paste? If the Clipboard is not a picture, how do I paste it?
In fact, we only use the Tclipboard.hasformat function to judge the Clipboard is not a picture on the line.