怎么在一个COMBOBOX的控件里的每一个ITEM前面加一个图标?

解决方案 »

  1.   

    Style:=csOwnerDrawVariable;
    OnMeMeasureItem事件中设置高度
    procedure TForm1.CBBoxDrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
    lrc,rrc:TRect;
    bc:TColor;
    begin
      with CBBox.Canvas do
      begin
         bc:=Brush.color;
         Brush.color:=clRed;
         lrc.left:=rect.left;
         lrc.right:=20;
         lrc.Top:=rect.Top;
         lrc.Bottom:=rect.Bottom;
         rrc.Left:=20;
         rrc.Right:=rect.right;
         rrc.Top:=rect.Top;
         rrc.Bottom:=rect.bottom;
         FillRect(lrc);
         if odSelected in State then Brush.color:=clLime
         else Brush.color:=clWhite;
         FillRect(rrc);
         Brush.color:=bc;
         Brush.Style:=bsClear;
         TextOut(26,Index*CBBox.ItemHeight+2,CBBox.Items.Strings[Index]);
      end;
    end;
      

  2.   

    procedure TFrmEdit.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
        text : string;
        off : integer;
        i,N : integer;
    begin
      N :=0;
      for i :=0 to Combobox2.Items.Count - 1 do
      begin
        if ComboBox2.Items[i] = 'D' then
          N :=i - 2;
      end;  ComboBox1.Canvas.FillRect( Rect );
      if Index <= N then
        ImageList6.Draw(combobox1.canvas,Rect.left+2,Rect.top+2,0)
      else
        ImageList6.Draw(combobox1.canvas,Rect.left+2,Rect.top+2,1);
      text :=combobox1.items.Strings[Index];
      off :=Trunc((Rect.bottom - Rect.top- combobox1.Canvas.TextHeight(text))/2);
      combobox1.Canvas.TextOut(Rect.left+imagelist6.width+2*2,Rect.top+off,text);
      

  3.   

    楼上的回答对的,写Combobox的OnDrawItem另:Delphi7里有这个控件的
      

  4.   

    用Delphi自帯的TComboBoxEx
    設定:ComboBoxEx1.Images := ImageList1;
       把图标装入ImageList1中...
      

  5.   

    放着win32里的comboboxEx不用,去写一大堆代码,真的昏死。