Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

星期四, 11月 08, 2007

CheckBox、RadioButton、ListBox

CheckBox
可以拿來做複選的方式。重要屬性如下:
checked : true 或 false ,gray及unchecked皆為 false,而 checked 為 true。
state : 如果 allowgrayed為true,則有三種狀態
type TCheckBoxState = (cbUnchecked, cbChecked, cbGrayed);
allowgrayed:是否需要灰階的選項
常用程式碼

function showState(state: TCheckBoxState):string;
begin
case state of
cbUnchecked : result:='unchecked';
cbChecked : result:='checked';
cbGrayed : result:='grayed';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
checkbox1.AllowGrayed:= not checkbox1.AllowGrayed;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if checkbox1.Checked=true then
showmessage('checkbox1 = true')
else
showmessage('checkbox1 = false');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
showmessage(showState(checkbox1.state));
end;



RadioButton
常放在Panel、RadioBox及GroupBox中,才能形成一組多選一的狀態

//先選擇一組內的所有Radio(shift選取),然後選擇共同的事件
var
blood : string;//blood為全域變數
procedure TForm1.RadioButton1Click(Sender: TObject);
var i: integer;
begin
blood:=Tradiobutton(sender).Caption + '型';
end;
//最後確定的按鈕就為
procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage( blood + #10); //#10多加(自己亂加的)跳行意思
end;
//動態加入radiobuttoon於radiogoup中
procedure TForm1.Button1Click(Sender: TObject);
begin
radiogroup1.Items.Add(edit1.Text);
end;
//將剛剛動態加入radiobuttoon清除
procedure TForm1.Button3Click(Sender: TObject);
begin
radiogroup1.Items.clear;
end;
//將剛剛動態加入radiobuttoon清除
procedure TForm1.Button4Click(Sender: TObject);
begin
radiogroup1.Columns:=2;
end;



ListBox

//單選,並得知ListBox1選哪一個
procedure TForm1.Button1Click(Sender: TObject);
begin
listbox1.MultiSelect:=false;
showmessage(listbox1.Items[listbox1.ItemIndex]);
end;
//排序或不排序,一直做反向處理
procedure TForm1.Button3Click(Sender: TObject);
begin
listbox1.Sorted:=not listbox1.Sorted;
end;
//加新的Item進去
procedure TForm1.aa1Click(Sender: TObject);
begin
listbox1.AddItem(edit1.Text ,nil );
end;
//刪除Item
procedure TForm1.delete1Click(Sender: TObject);
begin
listbox1.DeleteSelected;
end;
//顯示所有選到,這是可複選才要喔
procedure TForm1.showSelected1Click(Sender: TObject);
var
i: integer;
s: string;
begin
for i:= 0 to listbox1.Items.Count -1 do
begin
if listbox1.Selected[i] then
s:= s + ' ' + listbox1.Items.Strings[i];
end;



ComboBox
重要屬性
items
text
maxLength
dropDownCount
style
autocomplete
autodropdown//自動下拉到你要的

procedure TForm1.ComboBox1Click(Sender: TObject);
//加入一個新的Item
begin
listbox1.Items.Add(combobox1.Text );
end;

沒有留言: