C#winform listBox 行文本颜色 怎么做 本帖最后由 satdown 于 2009-09-30 13:00:06 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 明明有这样的控件,为什么不用,richTextBox 使用ListView控件,设置View为Details,隐藏列头,ListView支持给行文本设置颜色的。 设置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); } 我是在给ListView添加ListViewItem的时候设置的颜色。下面这个例子,希望有所帮助 ListViewItem lvi = new ListViewItem(); if (i % 2 == 0) { //控制背景颜色 lvi.BackColor = Color.FromArgb(240, 240, 255); //lvi.BackColor = Color.FromArgb(245, 245, 200); } 判断一下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); } } 求一个速度快的分页SQL 请教高手指点,关于c#中继承与死锁的问题? 太有疑问了这个…… 判断重复的问题, 我想了n久?求答! 如何利用datagridview做一个数据编辑表格 XmlDataSource的问题,哪位来指导一下呀? 菜鸟求教一程序代码(C#) .net真的一次编译到处运行吗? 请问在c#怎么样才能输入字符串呢?很多数字的 菜鸟问题,过来看一看!如何调整启动的顺序? 今天面试的程序题,求解答! 找一种c#的书,描述请进……
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);
}
下面这个例子,希望有所帮助 ListViewItem lvi = new ListViewItem();
if (i % 2 == 0)
{
//控制背景颜色
lvi.BackColor = Color.FromArgb(240, 240, 255);
//lvi.BackColor = Color.FromArgb(245, 245, 200);
}
判断一下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);
} }