本帖最后由 baiyuxiong 于 2009-11-16 09:57:02 编辑

解决方案 »

  1.   

    用listview的detail模式试试 这种可以加载图标
      

  2.   

    重载了listBox本身没有意义吧,listbox不能显示图片的,可以试试做个自定义控件,进行基类重载,然后传图片地址.
      

  3.   

    我不想用listview
    那个控件有其它地方不能满足我的需求。
      

  4.   

    DrawItemEventArgs 你看看这个里面。
    没做过WINFORM的东西,刚才看了下编译的代码,在执行ONDRAMITEM时有个委托,还没看完。。
      

  5.   

    为什么 重载listBox没意义?
    我画Items的时候,多画点儿东西就行了。重载相比自定义来说难度较低
      

  6.   

    vs2008using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication17
    {
        using XX;    public partial class Form1 : Form
        {
            public Form1()
            {            InitializeComponent();            supListBox LB = new supListBox();
                LB.Parent = this;            Bitmap Bmp = new Bitmap(10, 10);
                using (Graphics G = Graphics.FromImage(Bmp))
                    G.Clear(Color.Red);            LB.Items.Add("AAA", Bmp);
            }
        }    namespace XX
        {
            public static class X
            {
                /// <summary>
                /// X
                /// </summary>
                /// <param name="OC">XX</param>
                /// <param name="Obj">XXX</param>
                /// <param name="Ic">XXXX</param>
                public static void Add(this supListBox.ObjectCollection OC, Object Obj, Bitmap Bmp)
                {
                    OC.Add(new ObjEx(Obj, Bmp));
                }
            }
        }    class ObjEx
        {
            public Object Obj;
            public Bitmap Bmp;        public ObjEx(Object Obj, Bitmap Bmp)
            {
                this.Obj = Obj;
                this.Bmp = Bmp;
            }
        }    public class supListBox : System.Windows.Forms.ListBox
        {
            public supListBox()
            {
                this.DrawMode = DrawMode.OwnerDrawFixed;
            }        protected override void OnDrawItem(DrawItemEventArgs e)
            {
                ObjEx Obj = (ObjEx)this.Items[e.Index];
                Size S = TextRenderer.MeasureText(Obj.Obj.ToString(), this.Font);            e.DrawBackground();
                e.Graphics.DrawImage(Obj.Bmp, new Point(0, 0));
                e.Graphics.DrawString(Obj.Obj.ToString(), this.Font, new SolidBrush(e.ForeColor),
                    new Point((e.Bounds.Width - S.Width) / 2, (e.Bounds.Height - S.Height) / 2));
            }
        }
    }
      

  7.   

    Listbox