Delphi XE2 之 FireMonkey 入門(41) - 控件基礎: TListBox
TScrollBox -> TCustomListBox -> TListBox; 其元素項是 TListBoxItem 類型.
TListBox 的功能在 TCustomListBox 裡就完成了.
值得注意的變化是:
1、復選框(相關屬性: ShowCheckboxes、TListBoxItem.IsChecked)
2、交替背景(通過繼承還可以調整交替的背景色)
3、TListBoxItem 可調整大小、容納其它對象.
public
constructor Create(...); override; destructor Destroy; override; procedure Assign(...); override; procedure Clear; virtual; function DragChange(...): Boolean; dynamic; procedure SelectAll; procedure ClearSelection; procedure SelectRange(...); function ItemByPoint(...): TListBoxItem; function ItemByIndex(...): TListBoxItem; procedure Exchange(...); procedure AddObject(...); override; procedure RemoveObject(...); override; procedure Sort(...); override; property Count: Integer ...; property Selected: TListBoxItem ...; property Items: TStrings ...; property ListItems[Index: Integer]: TListBoxItem ...; property ItemIndex: Integer ...; end;
published
property StyleLookup; property AllowDrag; property CanFocus; property DisableFocusEffect; property TabOrder; property AlternatingRowBackground; property Columns; property HideSelectionUnfocused; property Items; property ItemIndex; property ItemWidth; property ItemHeight; property ListStyle; property MultiSelect; property Sorted; property ShowCheckboxes; property BindingSource; property OnChange; property OnChangeCheck; property OnCompare; property OnDragChange; end;
public
constructor Create(...); override; property Data: TObject ...; property Index: Integer ...; published
property IsChecked: Boolean ...; property IsSelected: Boolean ...; property AutoTranslate ...; property Font; property StyleLookup; property Text; property TextAlign ...; property WordWrap; end;
測試:
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
ListBox1.Align := TAlignLayout.alLeft;
ListBox1.ShowCheckboxes := True;
ListBox1.AlternatingRowBackground := True;
for i := to do
begin
ListBox1.Items.Add( + IntToStr(i));
ListBox1.ListItems[i].IsChecked := Odd(i);
end;
end;