【发布时间】:2021-05-14 14:56:16
【问题描述】:
如何将 ComboBox 的第一项(索引 0)设置为已选中?
procedure TForm1.FormCreate(Sender: TObject);
begin
with ComboBox1.Items do
begin
Add('1st Item');
Add('2nd Item');
Add('3rd Item');
end;
end;
// PS: Change the Style property of ComboBox1 to csOwnerDrawFixed
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
AnIcon: TIcon;
begin
AnIcon := TIcon.Create;
try
ImageList1.GetIcon(Index, AnIcon);
with Control as TComboBox do
begin
Canvas.Draw(Rect.Left, Rect.Top, AnIcon);
Canvas.TextOut(Rect.Left + ImageList1.Width, Rect.Top, Items[Index]);
end;
finally
AnIcon.Free;
end;
end;
【问题讨论】:
-
你试过
ComboBox1.ItemIndex := 0;吗?
标签: delphi combobox delphi-10.3-rio