我想在ComboBox中加入下拉图片,如何做?请高手指教。

解决方案 »

  1.   

    ComboBox中不行试试其他的控件
      

  2.   

    在formshow中初始化combobox中的图片:
        combobox.Clear;
        file:= 'c:\bmp\';
        filefound:=FindFirst(file+'*.bmp',faAnyFile,SearchRec);
        while filefound=0 do
        begin
          if (SearchRec.Name<>'.')and(SearchRec.Name<>'..')and (SearchRec.Attr<>faDirectory) then
          begin
             <font color =#ff0000><strong>Bitmap := TBitmap.Create; </font></strong>
             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).Canvas do
      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;