本帖最后由 csdsuper 于 2010-06-24 10:44:56 编辑

解决方案 »

  1.   

    一样可以设置;
    你的这个东西,不用listview,自己写个控件也很简单;只是没有时间帮你写而已
      

  2.   

    我发现ListVew有点像 就是像它的List模式下的方式,但是它的选中颜色怎么改呢,它的边框色怎么改呢
      

  3.   

    控件代码using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;namespace QiQi.Windows.Forms
    {
        public class QiQiListBox : Control
        {
            private readonly List<QiQiListBoxItem> _items;
            private Color _border_color;
            private int _item_height;        private Color _selected_back_color;
            private int _selected_index;        public QiQiListBox()
            {
                SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
                _items = new List<QiQiListBoxItem>();
                _item_height = 24;
                _selected_index = -1;
                _border_color = Color.FromArgb(245, 170, 114);
                _selected_back_color = Color.FromArgb(255, 237, 209);
            }        public Color BorderColor
            {
                get { return _border_color; }
                set { _border_color = value; }
            }        public Color SelectedBackColor
            {
                get { return _selected_back_color; }
                set { _selected_back_color = value; }
            }        public int SelectedIndex
            {
                get { return _selected_index; }
                set { _selected_index = value; }
            }        public int ItemHeight
            {
                get { return _item_height; }
                set { _item_height = value; }
            }        public void insert_item(QiQiListBoxItem item, int index)
            {
                _items.Insert(index, item);
            }        public void delete_item(int index)
            {
                _items.RemoveAt(index);
            }        protected override void OnPaintBackground(PaintEventArgs pevent)
            {
                base.OnPaintBackground(pevent);
                //边框
                using (var pen = new Pen(_border_color))
                {
                    Rectangle rect = DisplayRectangle;
                    rect.Width -= 1;
                    rect.Height -= 1;
                    pevent.Graphics.DrawRectangle(pen, rect);
                }
            }        protected override void OnPaint(PaintEventArgs e)
            {
                for (int i = 0; i < _items.Count; i++)
                {
                    draw_item(e.Graphics, i, i == _selected_index);
                }
            }        private void draw_item(Graphics g, int index, bool selected)
            {
                QiQiListBoxItem item = _items[index];
                Rectangle rect = get_item_rect(index);
                using (Brush bru = new SolidBrush(selected ? _selected_back_color : BackColor))
                {
                    g.FillRectangle(bru, rect);
                }
                //图标
                g.DrawImage(item.Image, 1, 1 + index*_item_height, 24, 24);
                Rectangle rect_text = rect;
                rect_text.Width -= 24;
                rect_text.X += 24 + 10;
                var sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                g.DrawString(item.Text, Font, Brushes.Black, rect_text, sf);
            }        private Rectangle get_item_rect(int index)
            {
                return new Rectangle(2, index*_item_height + 2, Width - 4, _item_height);
            }        public int hit_test(int x, int y)
            {
                for (int i = 0; i < _items.Count; i++)
                {
                    if (get_item_rect(i).Contains(x, y))
                        return i;
                }
                return -1;
            }        protected override void OnMouseDown(MouseEventArgs e)
            {
                base.OnMouseDown(e);
                int index = hit_test(e.X, e.Y);
                Graphics g = CreateGraphics();
                if (_selected_index != -1)
                    draw_item(g, _selected_index, false);
                if (index != -1)
                {
                    _selected_index = index;
                    draw_item(g, index, true);
                }
            }
        }    public class QiQiListBoxItem
        {
            public Image Image { get; set; }
            public string Text { get; set; }
            public object Tag { get; set; }
        }
    }
      

  4.   

    调用代码            list.insert_item(new QiQiListBoxItem
                                     {
                                         Image = Image.FromFile(@"f:\\temp\\i1.png"),
                                         Text = "智能秘书",
                                     }, 0);
                list.insert_item(new QiQiListBoxItem
                                     {
                                         Image = Image.FromFile(@"f:\\temp\\i2.png"),
                                         Text = "信息订阅",
                                     }, 0);
                list.insert_item(new QiQiListBoxItem
                                     {
                                         Image = Image.FromFile(@"f:\\temp\\i3.png"),
                                         Text = "空间信息",
                                     }, 0);
                list.Invalidate();100分 拿出来 
      

  5.   

    你把它改成从 ListBox 继承的。