响应ComboBox.DrawItem事件,该事件的DrawItemEventArgs参数提供以下几个有价值的对象:
Index      所要绘制的项的索引
Graphics   GDI+的主对象,用他的Graphics.DrawImage方法在你希望的位置上绘制图象。
Bounds     所要进行绘制的区域。
DrawItemEventArgs还有其他几个对象请参考SDK,有字体和背景色什么的。

解决方案 »

  1.   

    cometsky(找工作中,有意者CSDN短信联系) 
    兄弟能不能给各实例呀,先谢了
      

  2.   

    http://www.csharpproject.com/articles/winforms/combo_listboxes/ColorComboBox.aspx
    请参考这篇文章
      

  3.   

    我做过这个,代码如下
    如果DropDownStyle 是 DropDownList,代码这样写:private void DatabaseList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    { Rectangle textRect = new Rectangle(this.SmallDBIcon.Width + e.Bounds.X , e.Bounds.Y+1, e.Bounds.Width-4, e.Font.Height);
    //SolidBrush textBrush = new SolidBrush(SystemColors.WindowText); e.Graphics.DrawIcon(this.SmallDBIcon, e.Bounds.X, e.Bounds.Y);
    if(e.Index >= 0)
    {
    e.Graphics.DrawString(this.DatabaseList.Items[e.Index].ToString(), e.Font, SystemBrushes.WindowText, textRect, StringFormat.GenericDefault);
    }
    }如果DropDownStyle是DropDown,就把if判断去掉
    private void DatabaseList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
    Rectangle textRect = new Rectangle(this.SmallDBIcon.Width + e.Bounds.X , e.Bounds.Y+1, e.Bounds.Width-4, e.Font.Height);
    //SolidBrush textBrush = new SolidBrush(SystemColors.WindowText);//下面这句是画图的语句
    e.Graphics.DrawIcon(this.SmallDBIcon, e.Bounds.X, e.Bounds.Y); e.Graphics.DrawString(this.DatabaseList.Items[e.Index].ToString(), e.Font, SystemBrushes.WindowText, textRect, StringFormat.GenericDefault);
    }
      

  4.   

    private void Form1_Load(object sender, System.EventArgs e)
    {

    this.comboBox1.Items.Add(" one");
    this.comboBox1.Items.Add("  two");
    this.comboBox1.Items.Add(" three");
    this.comboBox1.Items.Add("  four");
    this.comboBox1.Items.Add("  five");
    this.comboBox1.Text=this.comboBox1.Items[0].ToString(); this.comboBox1.DrawMode=System.Windows.Forms.DrawMode.OwnerDrawVariable;
    this.comboBox1.DrawItem+=new DrawItemEventHandler(comboBox1_DrawItem);
    this.comboBox1.MeasureItem+=new MeasureItemEventHandler(comboBox1_MeasureItem); } private void comboBox1_MeasureItem(object sender,System.Windows.Forms.MeasureItemEventArgs e)
    {
                  
        e.ItemHeight=40;
        e.ItemWidth=100; } private void comboBox1_DrawItem(object sender,System.Windows.Forms.DrawItemEventArgs e)
    {
                   //图标   
    Icon []myicon=new Icon[5];
    myicon[0]=new Icon("f:\\1.ico");
    myicon[1]=new Icon("f:\\2.ico");
    myicon[2]=new Icon("f:\\3.ico");
    myicon[3]=new Icon("f:\\4.ico");
    myicon[4]=new Icon("f:\\5.ico");
           //设置绘图环境

    Graphics g=e.Graphics;

    //设置字体
    Font myfont=new Font("宋体",15,System.Drawing.FontStyle.Bold|FontStyle.Italic);
       
    Brush mybrush=System.Drawing.Brushes.Red;

    e.DrawFocusRectangle();
    e.DrawBackground();

      //绘图
    g.DrawIcon(myicon[e.Index],e.Bounds.X,e.Bounds.Y);//每一个item项
    g.DrawString(this.comboBox1.Items[e.Index].ToString(),myfont,mybrush,50,0);   
       

    }
      

  5.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=YJA3BSW8-2CES-4L6Q-K7V7-JDBERJEJC4C5