Delphi XE2 之 FireMonkey 入门(42) - 控件基础: TComboBox、TComboEdit

时间:2023-03-08 22:12:44
TListBox 有两个兄弟 TComboListBox、TComboEditListBox;
TComboBox、TComboEdit 虽不是不是从它们继承, 但分别包含了它们, 所以使用起来都有点像 TListBox.

TComboBox 更像 TListBox, 比 TComboEdit 多出了 Selected 等成员;
TComboEdit 是从 TCustomEdit 继承, 和 TEdit 是兄弟, 比 TComboBox 多出了 Text 等成员.

它们的公共常用属性:


DropDownCount //下拉列表行的数
ItemHeight    //
ItemIndex    //
Items        //
Count        //

测试:

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  { ComboBox1 }
  for i := to do
    ComboBox1.Items.Add(Format('Item_%d', [i]));
  with ComboBox1 do
  begin
    ItemIndex := ;
    DropDownCount := ;
    ListBox.UseSmallScrollBars := True;
    TListBox(ListBox).AlternatingRowBackground := True; //这个兄弟转换用得有点悬, 只是为了让 AlternatingRowBackground 属性暴露出来
  end;   { ComboEdit1 }
  ComboEdit1.Items.Assign(ComboBox1.Items);
  with ComboEdit1 do
  begin
    ItemIndex := ;
    DropDownCount := ;
    ListBox.UseSmallScrollBars := True;
    TListBox(ListBox).AlternatingRowBackground := True;
  end;
//  ComboEdit1.Text := 'Text';
end;