S
shyrain
Unregistered / Unconfirmed
GUEST, unregistred user!
我在formshow中初始化combobox中的图片:
combobox.Clear;
file:= 'c:/bmp/';
filefound:=FindFirst(file+'*.bmp',faAnyFile,SearchRec);
while filefound=0do
begin
if (SearchRec.Name<>'.')and(SearchRec.Name<>'..')and(SearchRec.Attr<>faDirectory)
then
begin
bitmap.LoadFromFile(file+SearchRec.Name);
//var bitmap: TBitmap;已经创建
ComboBox.Items.AddObject(SearchRec.Name, bitmap);
filefound:=FindNext(SearchRec);
end;
end;
findclose(SearchRec);
在ondrawitem事件中处理图像显示:
procedure comboboxDrawItem(Control: TWinControl;
Index: Integer;
Rect: TRect;
State: TOwnerDrawState);
var Bitmap: TBitmap;
destrect, sourcerect: TRect;
begin
with (Control as TComboBox).Canvasdo
begin
FillRect(Rect);
Bitmap := TBitmap(ComboBox.Items.Objects[Index]);
//显示图形
if Bitmap <> nil then
begin
destrect:=bounds(Rect.Left,Rect.Top,32,32);
sourcerect:=bounds(0, 0, 32,32);
BrushCopy(destrect, Bitmap, sourcerect, clWhite);
Offset := Bitmap.width;
end;
TextOut(Rect.Left + Offset +5, Rect.Top, Combobox.Items[Index]);
end;
end;
可是结果确是:显示的图片都是search到的最后一个图像文件,但所对应的string确实不同的
也就是说,BrushCopy()没有成功执行。为什么?
combobox.Clear;
file:= 'c:/bmp/';
filefound:=FindFirst(file+'*.bmp',faAnyFile,SearchRec);
while filefound=0do
begin
if (SearchRec.Name<>'.')and(SearchRec.Name<>'..')and(SearchRec.Attr<>faDirectory)
then
begin
bitmap.LoadFromFile(file+SearchRec.Name);
//var bitmap: TBitmap;已经创建
ComboBox.Items.AddObject(SearchRec.Name, bitmap);
filefound:=FindNext(SearchRec);
end;
end;
findclose(SearchRec);
在ondrawitem事件中处理图像显示:
procedure comboboxDrawItem(Control: TWinControl;
Index: Integer;
Rect: TRect;
State: TOwnerDrawState);
var Bitmap: TBitmap;
destrect, sourcerect: TRect;
begin
with (Control as TComboBox).Canvasdo
begin
FillRect(Rect);
Bitmap := TBitmap(ComboBox.Items.Objects[Index]);
//显示图形
if Bitmap <> nil then
begin
destrect:=bounds(Rect.Left,Rect.Top,32,32);
sourcerect:=bounds(0, 0, 32,32);
BrushCopy(destrect, Bitmap, sourcerect, clWhite);
Offset := Bitmap.width;
end;
TextOut(Rect.Left + Offset +5, Rect.Top, Combobox.Items[Index]);
end;
end;
可是结果确是:显示的图片都是search到的最后一个图像文件,但所对应的string确实不同的
也就是说,BrushCopy()没有成功执行。为什么?