delphi ComboBoxEx的组件如何在主选项增加图标和文字
1个回答
展开全部
//参考如下代码去做
//code by onesue
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ImgList, ComCtrls;
type
TForm1 = class(TForm)
ComboBoxEx1: TComboBoxEx;
ImageList1: TImageList;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
oneItem: TComboExItem;
index:Integer ;
begin
//直接添加
index:= ComboBoxEx1.Items.IndexOf('Test');
if index=-1 then
begin
oneItem:=ComboBoxEx1.ItemsEx.Add;
oneItem.Caption:='Test';
if ComboBoxEx1.Images <>nil then //要指定图片列表
begin
oneItem.ImageIndex:=1;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
index:Integer ;
begin
//间接制定图片
index:= ComboBoxEx1.Items.IndexOf('Test2');
if index=-1 then
ComboBoxEx1.Items.Add('Test2');
index:= ComboBoxEx1.Items.IndexOf('Test2');
if index<>-1 then
begin
if ComboBoxEx1.Images <>nil then //要指定图片列表
begin
ComboBoxEx1.ItemsEx[index].ImageIndex:=0;
end;
end ;
end;
end.
//code by onesue
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ImgList, ComCtrls;
type
TForm1 = class(TForm)
ComboBoxEx1: TComboBoxEx;
ImageList1: TImageList;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
oneItem: TComboExItem;
index:Integer ;
begin
//直接添加
index:= ComboBoxEx1.Items.IndexOf('Test');
if index=-1 then
begin
oneItem:=ComboBoxEx1.ItemsEx.Add;
oneItem.Caption:='Test';
if ComboBoxEx1.Images <>nil then //要指定图片列表
begin
oneItem.ImageIndex:=1;
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
index:Integer ;
begin
//间接制定图片
index:= ComboBoxEx1.Items.IndexOf('Test2');
if index=-1 then
ComboBoxEx1.Items.Add('Test2');
index:= ComboBoxEx1.Items.IndexOf('Test2');
if index<>-1 then
begin
if ComboBoxEx1.Images <>nil then //要指定图片列表
begin
ComboBoxEx1.ItemsEx[index].ImageIndex:=0;
end;
end ;
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询