[英]is it possible to have different colors of text in a textbox or listbox?
I'm not sure if it's possible. 我不确定是否可以。 I wrote a code like this: 我写了这样的代码:
listBox1.Items.Add("There are " + countu.ToString().Trim() + " u's");
listBox1.Font = new Font("Arial", 12, FontStyle.Bold);
listBox1.ForeColor = Color.Violet;
listBox1.Items.Add("There are " + j.ToString().Trim() + " vowels");
listBox1.ForeColor = Color.Blue;
When I executed this code, the color of the texts were blue. 当我执行此代码时,文本的颜色为蓝色。 I would like to have it first "violet" and then the next line of code blue. 我想先将其“紫罗兰色”,然后将其下一行代码蓝色。 Is it possible? 可能吗?
Cheers 干杯
You could create an owner-drawn listbox as described in MSDN here: 您可以按照MSDN此处所述创建所有者绘制的列表框:
ObjectListView , though it's not exactly a ListBox
, allows to do that. 尽管ObjectListView并不完全是ListBox
,但它可以做到这一点。 If you want ListBox
only, see this . 如果只需要ListBox
,请参见this 。
仅当您自己绘制所有内容(所有者绘制)时才有可能。
Try using listBox1.Items[currentItem].Attributes.CssStyle to set the color of each item on a granular level. 尝试使用listBox1.Items [currentItem] .Attributes.CssStyle在粒度级别上设置每个项目的颜色。
e: whoops, missed the windows-forms tag. e:糟糕,错过了windows-forms标签。 my bad. 我的错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.