本帖最后由 satdown 于 2009-09-30 13:00:06 编辑

解决方案 »

  1.   

    明明有这样的控件,为什么不用,richTextBox
      

  2.   

    使用ListView控件,设置View为Details,隐藏列头,ListView支持给行文本设置颜色的。
      

  3.   

    设置this.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
     private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
            {
                string s = this.listBox1.Items[e.Index].ToString();
                if (s.Contains("初始化成功"))
                {
                    e.Graphics.DrawString(s, this.Font, Brushes.Green,e.Bounds);
                }
                else if (s.Contains("初始化失败"))
                {
                    e.Graphics.DrawString(s, this.Font, Brushes.Red, e.Bounds);
                }
                else
                    e.Graphics.DrawString(s,this.Font,new SolidBrush(this.ForeColor),e.Bounds);
            }
      

  4.   

    我是在给ListView添加ListViewItem的时候设置的颜色。
    下面这个例子,希望有所帮助                ListViewItem lvi = new ListViewItem();
                    if (i % 2 == 0)
                    {
                        //控制背景颜色
                        lvi.BackColor = Color.FromArgb(240, 240, 255);
                        //lvi.BackColor = Color.FromArgb(245, 245, 200);
                    }
      

  5.   


    判断一下e.State 
      private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
            {
                string s = this.listBox1.Items[e.Index].ToString();
                if ((e.State & DrawItemState.Selected)==0)
                {
                    e.Graphics.FillRectangle(Brushes.White, e.Bounds);
                    if (s.Contains("初始化成功"))
                    {
                        e.Graphics.DrawString(s, this.Font, Brushes.Green, e.Bounds);
                    }
                    else if (s.Contains("初始化失败"))
                    {
                        e.Graphics.DrawString(s, this.Font, Brushes.Red, e.Bounds);
                    }
                    else
                        e.Graphics.DrawString(s, this.Font, new SolidBrush(this.ForeColor), e.Bounds);
                }
                else
                {
                    e.Graphics.FillRectangle(Brushes.Blue, e.Bounds);
                    e.Graphics.DrawString(s, this.Font, Brushes.White, e.Bounds);
                }        }