TClipBoard剪貼簿示例

2021-05-21 14:43:46 字數 2943 閱讀 4230

//拷貝端

unit unit1;

inte***ce

uses

windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, stdctrls, clipbrd, extctrls;

type

tform1 = class(tform)

button1: tbutton;

edit1: tedit;

edit2: tedit;

memo1: tmemo;

memo2: tmemo;

button2: tbutton;

button3: tbutton;

image1: timage;

copyimg: tbutton;

cutimg: tbutton;

procedure button1click(sender: tobject);

procedure button2click(sender: tobject);

procedure button3click(sender: tobject);

procedure copyimgclick(sender: tobject);

procedure cutimgclick(sender: tobject);

private

public

end;

varform1: tform1;

implementation

//字串拷貝

procedure tform1.button1click(sender: tobject);

begin

clipboard.astext := edit1.text;

edit2.text := clipboard.astext;

end;

procedure tform1.button2click(sender: tobject);

begin

//settextbuf用於把超過255個字元的字串拷貝到剪貼簿

clipboard.settextbuf(pchar(memo1.text));

memo2.text := clipboard.astext;

end;

字串拷貝 拷貝到程式二中

procedure tform1.button3click(sender: tobject);

begin

clipboard.astext := edit1.text;

end;

//影象拷貝

procedure tform1.copyimgclick(sender: tobject);

begin

clipboard.assign(image1.picture);

end;

//影象剪下:首先把影象拷貝到剪貼簿,然後在原來位置用空白影象進行覆蓋

procedure tform1.cutimgclick(sender: tobject);

vararect: trect;

begin

clipboard.assign(image1.picture);//把image1上的影象拷貝到剪貼簿

with image1.canvas do

begin

copymode := cmwhiteness;

arect := rect(0,0,image1.width,image1.height);//空白影象

copyrect(arect,image1.canvas,arect);//覆蓋

copymode := cmsrccopy;

end;

end;

end.

//貼上端

unit unit2;

inte***ce

uses

windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, stdctrls, clipbrd, extctrls;

type

tform1 = class(tform)

pastetxt: tbutton;

label1: tlabel;

pasteimg: tbutton;

image1: timage;

procedure pastetxtclick(sender: tobject);

procedure pasteimgclick(sender: tobject);

private

public

end;

varform1: tform1;

implementation

//字串拷貝 資料來源從程式一中

procedure tform1.pastetxtclick(sender: tobject);

begin

label1.caption := clipboard.astext;

end;

//影象貼上 資料來源從程式一中

procedure tform1.pasteimgclick(sender: tobject);

varbitmap: tbitmap;

begin

if clipboard.hasformat(cf_bitmap) then //檢測剪貼簿上的資料格式

begin

bitmap := tbitmap.create;

trybitmap.assign(clipboard); //拷貝剪貼簿

image1.canvas.draw(0,0,bitmap);

finally

bitmap.free; //釋放記憶體

end;

end;

end;

end.

操作剪貼簿

剪貼簿 一 將資料送到剪貼簿 1 記憶體配置 hglobal hglobal hglobal globalalloc ghnd gmem share,lstrlen ptext 1 sizeof tchar 為什麼不用malloc 在windows中執行的應用程式之間必須要共享剪貼簿所儲存的記憶體塊...

剪貼簿相關

public const int wm user 0x400 public const int wm cap edit copy wm user 30 dllimport user32.dll static extern bool sendmessage intptr hwnd,int wmsg,s...

剪貼簿功能

1,複製貼上字串 這個是需要輸入的資訊,即是要複製的資訊 uitextfield textfild uitextfield alloc init self.textfild textfild textfild.placeholder 請輸入資訊 textfild.font uifont system...