ListBox combobox的常用功能
delphi TStringList 用法詳解
//TStringList 常用方法與屬性 :
var
? List: TStringList;
? i: Integer;
begin
? List := TStringList.Create;
? List.Add('Strings1');?????????? {添加}
? List.Add('Strings2');
? List.Exchange(0,1);???????????? {置換}
? List.Insert(0,'Strings3');????? {插入}
? i := List.IndexOf('Strings1');? {第一次出現的位置}
? List.Sort;????????????????????? {排序}
? List.Sorted := True; ? {指定排序}
? List.Count;???????????????????? {總數}
? List.Text;????????????????????? {文本集合}
? List.Delete(0);???????????????? {刪除, 0是第一個數據}
? List.LoadFromFile('c:/tmp.txt');{打開}
? List.SaveToFile('c:/tmp.txt');? {保存}
? List.Clear;???????????????????? {清空}
? List.Free;????????????????????? {釋放}
end;
combobox1.Items.Add(edit1.Text); //將編輯框內容添加到combobox
edit1.Text:=combobox1.Items[0] ;
procedure sortfunc(ListBox:TListBox);
var
??I,J:Integer;
??temp:string;
begin
??with??ListBox??do
??begin
???for i:=0 to Count-1???do
????for j:=i to Count-1???do
??????if StrToInt(Items[i])>StrToInt(Items[j])???then
????????begin
??????????temp:=Items[i];
??????????Items[i]:=Items[j];
??????????Items[j]:=temp;
????????end;
??end;
end; listbox排序 1 sort {產生隨機數}
procedure?TForm1.Button1Click(Sender:?TObject);
var
??result:Integer;
??i:Integer;
begin
??ListBox1.Clear;
??for?i:=0?to?StrToInt(Edit1.Text)?do
??begin
??????Randomize;
??????Result:=Random(100)+1;
??????listbox1.Items.Add(IntToStr(result));
??end;
end;
{進行排序}
procedure?TForm1.Button5Click(Sender:?TObject);
var
I,J:Integer;
temp:string;?{速度有慢}
begin
??with??ListBox1??do
??begin
???for?i:=0?to?Count-1???do
????for?j:=i?to?Count-1???do
??????if?StrToInt(Items[i])>StrToInt(Items[j])???then
????????begin
??????????temp:=Items[i];
??????????Items[i]:=Items[j];
??????????Items[j]:=temp;
????????end;
??end;
end; ? ? {添加Edit1.text}
???if ListBox1.Items.IndexOf(Edit1.Text)<0 then??ListBox1.Items.Add(Edit1.Text);
???Edit1.SetFocus;
{添加listbox1選中的那一項}
????listbox2.Items.Add(ListBox1.Items[listbox1.ItemIndex]);
{刪除選中的項目}
??ListBox2.Items.Delete(ListBox2.ItemIndex);
??ListBox2.DeleteSelected; //刪除選中的項目
{清空列表框}
ListBox1.Items.Clear;?
listbox2.Clear;
{全選}
??ListBox1.MultiSelect:=True;
??ListBox1.SelectAll;
{如何判斷 listbox中的內容為空}
????if???listbox1.Items.Count=0??then??{ 為空};
{全部添加}
var
??i:Integer;
begin
??for i:=0 to ListBox1.Count-1 do
??begin
???ListBox2.Items.Add(listbox1.Items[i]);??//循環添加
??end;
end;
{使第1項被高亮選中}
????ListBox1.selected[0]:=True];//listbox1的選中項目
{listbox1的選中項目}
????Edit1.Text:=ListBox1.Items[ListBox1.ItemIndex];
{在第1行插入字符}
????ListBox1.Items.Insert(0,Edit1.Text); {先判斷后添加,不添加列表已存在的信息 } ?? if ListBox1.Items.IndexOf(Edit1.Text)<0 then? ListBox1.Items.Add(Edit1.Text); ?? if ComboBox1.Items.IndexOf(Edit1.Text)<0 then? ComboBox1.Items.Add(Edit1.Text); ? //listbox dragDrop DragOver
procedure TForm1.Edit1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := True;
end;
procedure TForm1.Edit1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
(Sender as TEdit).Text := (Source as TListBox).Items[(Source as TListBox).ItemIndex];
end; ? // Edit Label配合ListBox
Label1.Caption := Listbox1.Items[Listbox1.ItemIndex];
Edit1.text := Listbox1.Items[Listbox1.ItemIndex]; ? ? ? //CheckListBox1常用屬性和方法事件 ? //列表成員的 序列說明 第1位 0 第2位 1 ... 第n位 n-1 不在成員類 -1 ? //在項目中添加字符串(子項目的最后一位接著添加) ????? CheckListBox1.Items.Add(edit1.Text); ? //全選 高亮選中Selected ???? CheckListBox1.MultiSelect := True; ???? CheckListBox1.SelectAll; ? //全選 Checked All procedure TForm1.Button11Click(Sender: TObject); var i :integer; begin ? for i := 0 to CheckListBox1.Items.Count - 1 do ??? begin ????? CheckListBox1.Checked[i] := True;//反選設置為False ??? end; end; ? //讓第n行被高亮選中 CheckListBox1.Selected[1]:=true;//第2行 ? //取消高亮選中 ? CheckListBox1.ClearSelection; ? //第3行的項目灰色不可用 CheckListBox1.ItemEnabled[2] := False;//True可用 ? //刪除高亮選中的項目,(只管高亮選中就會被刪除,和checked是否無關) ??????? CheckListBox1.DeleteSelected;//刪除選中項目,即使該給項目 沒勾上也會被刪除 ? //刪除已勾選的中項目 procedure TForm1.Button5Click(Sender: TObject); var i : integer; begin for i := CheckListBox1.Items.Count-1 downto 0 do //從后面往前面刪 ?? begin ?? if CheckListBox1.Checked[i] then ????? begin ???????? CheckListBox1.Items.Delete(i); ????? end; ?? end; end; ? //清空項目 ? CheckListBox1.Items.Clear; ? //將CheckListBox1的全部添加到CheckListBox2的Items中 ? procedure TForm1.Button1Click(Sender: TObject); var i:Integer; begin CheckListBox2.Items.Clear; for i := CheckListBox1.Items.Count - 1 downto 0 do ?? begin ????? CheckListBox2.Items.Add(CheckListBox1.Items[i]); ?? end; end; ? //CheckListBox1的items操作,如單擊CheckListBox1第1項彈出消息??? ? //items的拖拽調換items的位置??? //改變選中行的背景顏色??? //CheckListBox1信息 讀取 和寫入 ? ?
來自為知筆記(Wiz)
轉載于:https://www.cnblogs.com/xe2011/archive/2012/05/26/2518892.html
總結
以上是生活随笔為你收集整理的ListBox combobox的常用功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 上传参数
- 下一篇: 用Reflector和FileDisas