不能在列表框中设置标签的颜色为什么? [英] cant set color of label in listbox why?
本文介绍了不能在列表框中设置标签的颜色为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
System.Windows.Forms.Label lbl = new System.Windows.Forms.Label();
lbl.ForeColor = System.Drawing.Color.Blue;
string txt =+==++文件夹标题:++ sub ++ siteColName +;
var display = lbl.Text = txt.ToString();
listboxLogging.Items.Add(display + Environment.NewLine);
解决方案
你没有把标签加入在列表框中,您将文本放入列表框。
文本没有颜色概念。
设置列表框中项目的颜色实际上非常困难 - 您可以使用ListView。添加完项目后,您可以更改该项目的属性(项目的NB,而不是文本)
或者如果你真的想要使用您可以自己绘制颜色的列表框 - 查看一些建议此处 [ ^
System.Windows.Forms.Label lbl = new System.Windows.Forms.Label(); lbl.ForeColor = System.Drawing.Color.Blue; string txt = " " + "==" + " " + "Folders title:" + " " + sub + " " + siteColName + " "; var display= lbl.Text = txt.ToString(); listboxLogging.Items.Add( display + Environment.NewLine);
解决方案
You are not putting the label "into" the listbox, you are putting the text into the list box.
Text does not have a concept of colour.
It's actually quite difficult to set the colour of items in a listbox - you could use a ListView instead. Once you have added the item you can change the properties of that item (NB of the item, not the "text")
Or if you really want to use a Listbox you can "draw" the colour yourself - see some suggestions here[^]
这篇关于不能在列表框中设置标签的颜色为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文