在style里设置csOwnerDrawFixed后,再下面代码加载图标...可这样ComboBox1.Items.Add就起不了作用,编辑不了内容! 请问怎样才可以用Add添加内容 ?procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
lBitmap: TBitmap;
begin
with (Control as TCombobox).Canvas do
begin
FillRect(Rect);
lBitmap :=TBitmap.Create;
if imagelist1.GetBitmap(index,lBitmap) then
BrushCopy(Bounds(Rect.Left + 2,Rect.Top,lBitmap.Width,lBitmap.Height),lBitmap,Bounds(0,0,lBitmap.Width,lBitmap.Height),clRed);
end;
end;procedure TForm1.FormActivate(Sender: TObject);
begin
if ComboBox1.Items.Count <> ImageList1.Count then
begin
ComboBox1.Items.Text := StringOfChar(#13, ImageList1.Count);
Combobox1.ItemIndex :=0;
end;
end;
Rect: TRect; State: TOwnerDrawState);
var
lBitmap: TBitmap;
begin
with (Control as TCombobox).Canvas do
begin
FillRect(Rect);
lBitmap :=TBitmap.Create;
if imagelist1.GetBitmap(index,lBitmap) then
BrushCopy(Bounds(Rect.Left + 2,Rect.Top,lBitmap.Width,lBitmap.Height),lBitmap,Bounds(0,0,lBitmap.Width,lBitmap.Height),clRed);
end;
end;procedure TForm1.FormActivate(Sender: TObject);
begin
if ComboBox1.Items.Count <> ImageList1.Count then
begin
ComboBox1.Items.Text := StringOfChar(#13, ImageList1.Count);
Combobox1.ItemIndex :=0;
end;
end;
Rect: TRect; State: TOwnerDrawState);
var
lBitmap: TBitmap;
begin
with (Control as TCombobox).Canvas do
begin
FillRect(Rect);
lBitmap := TBitmap.Create;
if imagelist1.GetBitmap(index, lBitmap) then
BrushCopy(Bounds(Rect.Left + 2, Rect.Top, lBitmap.Width, lBitmap.Height),
lBitmap, Bounds(0, 0, lBitmap.Width, lBitmap.Height), clRed);
//位置再自己调一下。
TextOut(Rect.Left,Rect.Top,(Control as TComboBox).Items[index]);
end;
end;