怎样在combobox中加入图片? 有这样的控件包, lmd. abc里头都有。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面是我的一段程序在listbox和combobox中加入图片unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TForm) Panel1: TPanel; Label2: TLabel; ListBox1: TListBox; ComboBox1: TComboBox; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); private { Private declarations } public { Public declarations } end;var Form1: TForm1; MyBitmap1, MyBitmap2, MyBitmap3, MyBitmap4: TBitmap; implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);beginMyBitmap1 := TBitmap.Create; MyBitmap1.LoadFromFile('.\1.bmp'); MyBitmap2 := TBitmap.Create; MyBitmap2.LoadFromFile('.\2.bmp'); MyBitmap3 := TBitmap.Create; MyBitmap3.LoadFromFile('.\3.bmp'); MyBitmap4 := TBitmap.Create; MyBitmap4.LoadFromFile('.\4.bmp'); ComboBox1.Items.AddObject('Bitmap1', MyBitmap1); ComboBox1.Items.AddObject('Bitmap2', MyBitmap2); ComboBox1.Items.AddObject('Bitmap3', MyBitmap3); ComboBox1.Items.AddObject('Bitmap4', MyBitmap4); ListBox1.Items.AddObject('Bitmap1', MyBitmap1); ListBox1.Items.AddObject('Bitmap2', MyBitmap2); ListBox1.Items.AddObject('Bitmap3', MyBitmap3); ListBox1.Items.AddObject('Bitmap4', MyBitmap4);end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin MyBitmap1.Free; MyBitmap2.Free; MyBitmap3.Free; MyBitmap4.Free;end;procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);var Bitmap: TBitmap; Offset: Integer; begin offset:=0; with ComboBox1.Canvas do begin FillRect(Rect); Bitmap := TBitmap(ComboBox1.Items.Objects[Index]); if Bitmap <> nil then {粘贴图片} begin{适当的空档使图片关系分明,clred为透明色} BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width, Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height), clred); Offset := Bitmap.width + 8; {图片与文字的间隔,以组件的Left属性计算} end; TextOut(Rect.Left + Offset, Rect.Top, ComboBox1.Items[Index]); {显示文字}end;end;procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);var Bitmap: TBitmap; Offset: Integer; begin offset:=0; with ListBox1.Canvas do begin FillRect(Rect); Bitmap := TBitmap(ListBox1.Items.Objects[Index]); if Bitmap <> nil then{粘贴图片} begin BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width, Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height), clRed); Offset := Bitmap.width + 8; {图片与文字的间隔,以组件的Left属性计算} end; TextOut(Rect.Left + Offset, Rect.Top, ListBox1.Items[Index]); {显示文字} end;end;end. xe2界面支持unicode吗 大家好!请问怎么在IE中响应activefrom里面的onpaint事件 读取swf文件中影片的大小 DELPHI2009 游戏角色名称无法显示,要不就是乱码? 问您一个问题! 关于系统信息提示的设计 两个问题(解决立即放分) 真的就没人会吗?请教大侠:在一个Panel里怎么显示另外一个EXE文件?或OCX文件?在线等待! 新手求助 怎样用代码控制DBGrid的标题栏! 怎样编译单个可独立运行的EXE文件?(无需任何库支持) 这个AdoConnection应如何写?
在listbox和combobox中加入图片unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Panel1: TPanel;
Label2: TLabel;
ListBox1: TListBox;
ComboBox1: TComboBox;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
MyBitmap1, MyBitmap2, MyBitmap3, MyBitmap4: TBitmap;
implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
MyBitmap1 := TBitmap.Create;
MyBitmap1.LoadFromFile('.\1.bmp');
MyBitmap2 := TBitmap.Create;
MyBitmap2.LoadFromFile('.\2.bmp');
MyBitmap3 := TBitmap.Create;
MyBitmap3.LoadFromFile('.\3.bmp');
MyBitmap4 := TBitmap.Create;
MyBitmap4.LoadFromFile('.\4.bmp');
ComboBox1.Items.AddObject('Bitmap1', MyBitmap1);
ComboBox1.Items.AddObject('Bitmap2', MyBitmap2);
ComboBox1.Items.AddObject('Bitmap3', MyBitmap3);
ComboBox1.Items.AddObject('Bitmap4', MyBitmap4);
ListBox1.Items.AddObject('Bitmap1', MyBitmap1);
ListBox1.Items.AddObject('Bitmap2', MyBitmap2);
ListBox1.Items.AddObject('Bitmap3', MyBitmap3);
ListBox1.Items.AddObject('Bitmap4', MyBitmap4);
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MyBitmap1.Free;
MyBitmap2.Free;
MyBitmap3.Free;
MyBitmap4.Free;
end;procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var Bitmap: TBitmap; Offset: Integer;
begin
offset:=0;
with ComboBox1.Canvas do
begin
FillRect(Rect);
Bitmap := TBitmap(ComboBox1.Items.Objects[Index]);
if Bitmap <> nil then {粘贴图片}
begin{适当的空档使图片关系分明,clred为透明色}
BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,
Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
Bitmap.Height), clred);
Offset := Bitmap.width + 8; {图片与文字的间隔,以组件的Left属性计算}
end;
TextOut(Rect.Left + Offset, Rect.Top, ComboBox1.Items[Index]); {显示文字}
end;
end;procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var Bitmap: TBitmap; Offset: Integer;
begin
offset:=0;
with ListBox1.Canvas do
begin
FillRect(Rect);
Bitmap := TBitmap(ListBox1.Items.Objects[Index]);
if Bitmap <> nil then{粘贴图片}
begin
BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,
Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
Bitmap.Height), clRed);
Offset := Bitmap.width + 8; {图片与文字的间隔,以组件的Left属性计算}
end;
TextOut(Rect.Left + Offset, Rect.Top, ListBox1.Items[Index]); {显示文字}
end;
end;end.