我用下代码实现了在ComboBox前加载图标,但有两个地方还没搞懂1, 为什么选择框那里有个矩形框围着,要怎样才能去掉 ?
2,ImageList1里我只放了一个图标,但ComboBox里我Add了很多项,怎样让每项内容前面都显示图标
谢谢procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
         Rect: TRect; State: TOwnerDrawState);
begin
  ComboBox1.Canvas.FrameRect(Rect);
     //在组合框中绘制图标
  ImageList1.Draw(ComboBox1.Canvas,Rect.Left,Rect.Top,Index,true);
    //在组合框中绘制文本
  ComboBox1.Canvas.TextOut(Rect.Left+20,Rect.Top,ComboBox1.Items.Strings[Index]);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
   Combobox1.ItemIndex :=0;
end;

解决方案 »

  1.   

    ImageList1里我只放了一个图标,但ComboBox里我Add了很多项,怎样让每项内容前面都显示图标
    ===================================================================================ImageList1.Draw(ComboBox1.Canvas,Rect.Left,Rect.Top,0,true);
      

  2.   

    谢谢,行了...第一问题,我觉得是跟这句有关 ComboBox1.Canvas.FrameRect(Rect);但不知道怎样改
      

  3.   

    procedure TfrmMachSetting.listMachNoSelectItem(Sender: TObject; Item: TListItem; Selected: Boolean);
    begin
      if (Selected = true) then//注意这里
      begin
        Item.Selected := false;//注意这里
        Exit;  
      end;
    end;
    但是还要加判断,不然你会全部都选不上的