在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;

解决方案 »

  1.   

    用这个选项不行吗csOwnerDrawVariable
      

  2.   

    没有画文字?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);
    //位置再自己调一下。
        TextOut(Rect.Left,Rect.Top,(Control as TComboBox).Items[index]);
      end;
    end;
      

  3.   

    文字是可以编辑了,但是是另起一行...我是想把Add的内容画在图标的后面...恩,最后的结果是想通过Add添加多行内容,点下拉的的时候每一项的都有图标和文字