全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3526
推到 Plurk!
推到 Facebook!

複製listbox的內容

 
老大仔
尊榮會員


發表:78
回覆:837
積分:1088
註冊:2006-07-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-01-26 19:16:12 IP:220.132.xxx.xxx 訂閱
請問各位大大~~
我想要把listbox所點到的內容複製起來
然後想要貼到記事本或是word中
請問要怎麼寫呢@@?
謝謝
lichun1228
一般會員


發表:16
回覆:17
積分:11
註冊:2003-12-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-01-28 20:44:13 IP:220.132.xxx.xxx 訂閱
指定要的路徑 直接存起來就行了 listbox->Items->SaveToFile('C:\123.txt');
===================引 用 文 章===================
請問各位大大~~
我想要把listbox所點到的內容複製起來
然後想要貼到記事本或是word中
請問要怎麼寫呢@@?
謝謝
老大仔
尊榮會員


發表:78
回覆:837
積分:1088
註冊:2006-07-06

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-01-29 13:22:24 IP:220.132.xxx.xxx 訂閱
不好意思~不是這樣子滴
是我表達的不清楚>"<
我所要的功能是指~當我按了listbox中的某一個item時
也要同時有ctrl c的功能把該item的內容存起來(是存到剪貼簿是吧?)
然後這樣一來我才可以在一些應用程式上(word、記事本、excel、IE...等等)使用貼上
不知道這樣子表達有人懂嗎@@?


===================引 用 文 章===================
指定要的路徑 直接存起來就行了 listbox->Items->SaveToFile('C:\123.txt');
===================引 用 文 章===================

請問各位大大~~
我想要把listbox所點到的內容複製起來
然後想要貼到記事本或是word中
請問要怎麼寫呢@@?
謝謝
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-01-29 14:31:27 IP:59.124.xxx.xxx 未訂閱
參考 http://www.swissdelphicenter.ch/torry/showcode.php?id=640 這一篇
不過這一篇是複製所有的 TListBox 的 Items, 你再依自己需要修改.

uses
Clipbrd;

procedure ListBoxToClipboard(ListBox: TListBox;
BufferSize: Integer;
CopyAll: Boolean);
var
Buffer: PChar;
Size: Integer;
Ptr: PChar;
I: Integer;
Line: string[255];
Count: Integer;
begin
if not
Assigned(ListBox) then
Exit;

GetMem(Buffer, BufferSize);
Ptr := Buffer;
Count := 0;
for I := 0 to ListBox.Items.Count - 1 do
begin
Line := ListBox.Items.strings[I];
if not CopyAll and ListBox.MultiSelect and (not ListBox.Selected[I]) then
Continue;
{ Check buffer overflow }
Count := Count Length(Line) 3;
if Count = BufferSize then
Break;
{ Append to buffer }
Move(Line[1], Ptr^, Length(Line));
Ptr := Ptr Length(Line);
Ptr[0] := #13;
Ptr[1] := #10;
Ptr := Ptr 2;
end;
Ptr[0] := #0;
ClipBoard.SetTextBuf(Buffer);
FreeMem(Buffer, BufferSize);
end;

procedure ClipboardToListBox(ListBox: TListbox);
begin
if not
Assigned(ListBox) then
Exit;

if not Clipboard.HasFormat(CF_TEXT) then
Exit;

Listbox.Items.Text := Clipboard.AsText;
end;


//Copy all items from Listbox1 to the clipboard
procedure TForm1.Button1Click(Sender: TObject);
begin
ListBoxToClipboard(ListBox1, 1024, True);
end;

//Paste items in clipboard to Listbox2
procedure TForm1.Button2Click(Sender: TObject);
begin
ClipboardToListBox(Listbox2);
end;

//Copy only selected items from Listbox1 to the clipboard
procedure TForm1.Button3Click(Sender: TObject);
begin
ListBoxToClipboard(Listbox1, 1024, False);
end;


老大仔
尊榮會員


發表:78
回覆:837
積分:1088
註冊:2006-07-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-01-30 12:11:37 IP:220.140.xxx.xxx 訂閱
謝謝hagar大大~
我已經了解要怎麼去使用它了
原來還可以有更多的用法
讓我學到了更多
謝謝~~

//////
因為是hagar給了正解
所以結案囉~~^^

系統時間:2024-05-17 13:32:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!