应用场景:
    由于我想在ComboBox的每一项上都绑定一小图标,但Visual Studio提供的ComboBox不能实现,所以自己找了方法重写了ComboBox控件,来实现和图标的绑定。代码如下:
   public class ImageComboBoxItem:Object
    {
        #region 成员变量
        private Color foreColor=Color.FromKnownColor(KnownColor.Transparent);
        private bool bold = false;
        private int imageIndex = -1;
        private object tag = null;
        private string text = null;
        #endregion        #region 构造函数
        public ImageComboBoxItem()
        { }        public ImageComboBoxItem(string Text)
        {
            text = Text;
        }        public ImageComboBoxItem(string Text, int ImageIndex):this(Text)
        {
            imageIndex = ImageIndex;
        }        public ImageComboBoxItem(string Text, int ImageIndex, bool Bold)
            : this(Text, ImageIndex)
        {
            bold = Bold;
        }        public ImageComboBoxItem(string Text, int ImageIndex, bool Bold, Color ForeColor)
            : this(Text, ImageIndex, Bold)
        {
            foreColor = ForeColor;
        }        public ImageComboBoxItem(string Text, int ImageIndex, bool Bold, Color ForeColor, Object Tag)
            : this(Text, ImageIndex, Bold, ForeColor)
        {
            tag = Tag;
        }
        #endregion        #region 属性
        /// <summary>
        /// 文本颜色
        /// </summary>
        public Color ForeColor
        {
            get { return foreColor; }
            set { foreColor = value; }
        }        /// <summary>
        /// 字体加粗
        /// </summary>
        public bool Bold
        {
            get { return bold; }
            set { bold = value; }
        }        /// <summary>
        /// 附加数据
        /// </summary>
        public Object Tag
        {
            get { return tag; }
            set { tag = value; }
        }        /// <summary>
        /// 图标索引
        /// </summary>
        public int ImageIndex
        {
            get { return imageIndex; }
            set { imageIndex = value; }
        }        /// <summary>
        /// 项目文本
        /// </summary>
        public string Text
        {
            get { return text; }
            set { text = value; }
        }
        #endregion        public override string ToString()
        {
            return text;
        }
    }    /// <summary>
    /// 带图标的ComoBox控件
    /// </summary>
    public class ImageComboBox : ComboBox
    {
        private ImageList imgs = new ImageList();        #region 构造函数
        public ImageComboBox()
        {
            //设置绘制模式
            this.DrawMode = DrawMode.OwnerDrawFixed;
        }
        #endregion        #region 属性
        public ImageList ImageList
        {
            get { return imgs; }
            set { imgs = value; }
        }
        #endregion        /// <summary>
        /// 重写绘制Item的过程
        /// </summary>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();
            if (e.Index < 0)
            {
                e.Graphics.DrawString(this.Text, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + imgs.ImageSize.Width, e.Bounds.Top);
            }
            else
            {
                //是否ImageComboBoxItem
                if (this.Items[e.Index].GetType() == typeof(ImageComboBoxItem))
                {
                    ImageComboBoxItem item = (ImageComboBoxItem)this.Items[e.Index];                    //获取颜色和字体
                    Color foreColor = (item.ForeColor != Color.FromKnownColor(KnownColor.Transparent)) ? item.ForeColor : e.ForeColor;
                    Font font = item.Bold ? (new Font(e.Font, FontStyle.Bold)) : e.Font;                    // -1:没有图标
                    if (item.ImageIndex != -1)
                    {
                        //画图标和文本
                        this.ImageList.Draw(e.Graphics, e.Bounds.Left, e.Bounds.Top, item.ImageIndex);
                        e.Graphics.DrawString(item.Text, font, new SolidBrush(foreColor), e.Bounds.Left + imgs.ImageSize.Width, e.Bounds.Top);
                    }
                    else//画文本
                        e.Graphics.DrawString(item.Text, font, new SolidBrush(foreColor), e.Bounds.Left + imgs.ImageSize.Width, e.Bounds.Top);
                }
                else
                    e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + imgs.ImageSize.Width, e.Bounds.Top);
                base.OnDrawItem(e);
            }
        }
    }遇到的问题:
    在winform上添加该控件后,自己在ImageList属性里,加入图片时,总提示“参数必须是Image类型,参数名value”。所有图片类型都不行,各位大侠帮帮忙,谢啦