我设置的: private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            string s = this.listBox1.Items[e.Index].ToString();
            Brush b;
            switch (s)
            {
                case "成功":
                    b = new SolidBrush(Color.Blue);
                    break;
                case "失败":
                    b = new SolidBrush(Color.Red);
                    break;
                default:
                    b = new SolidBrush(this.ForeColor);
                    break;
            }
            e.Graphics.DrawString(s, this.Font, b, e.Bounds);
        }
为什么listBOx1不能选定项了?

解决方案 »

  1.   

    --可以的噢,前台加入一个TextBox(textBox1)和一个ListBox(listBox1),后台代码如下public Form9()
            {
                InitializeComponent();
            }        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
            {
                string s = this.listBox1.Items[e.Index].ToString();
                Brush b;
                switch (s)
                {
                    case "成功":
                        b = new SolidBrush(Color.Blue);
                        break;
                    case "失败":
                        b = new SolidBrush(Color.Red);
                        break;
                    default:
                        b = new SolidBrush(this.ForeColor);
                        break;
                }
                e.Graphics.DrawString(s, this.Font, b, e.Bounds);
            }        private void Form9_Activated(object sender, EventArgs e)
            {
                listBox1.Items.Clear();
                listBox1.Items.AddRange(new Object[] { "成功", "失败", "其他" });
            }        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                this.textBox1.Text = this.listBox1.SelectedItem.ToString();
            }
      

  2.   

    也不知道啥原因,我加上一句:e.DrawBackground();
    就可以在listBox中选定项了
    啥原因?
      

  3.   

    可以选定,只是没有画出来吧
    e.DrawBackground()就是把选定的哪个蓝条画出来,你也可以不使用它,自己画其它颜色