列表框中的c#颜色 [英] c # color in listbox

查看:60
本文介绍了列表框中的c#颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何设置背景颜色或仅更改列表框中文本的颜色,以便在查询期间发生错误时,该项目将变为红色?

how can i put a background color or just simply change the color of a text in a listbox so that when an error occur during a query, the item would simply be color red?

推荐答案

这不像设置属性那样简单!基本上,您必须自己绘制它...这里有一个示例:堆栈溢出 [ ^ ]
It''s not as simple as just setting a property! Basically, you have to draw it yourself... There is an example here: Stack overflow[^]


这是我的控件,可以执行此操作 [ ^ ]. (它还会执行其他一些操作-如果实际上您想要的只是不同颜色的文本,则Griff链接到的所有者绘制解决方案可能会完成这项工作.)它并不是应有的琐碎事情.
Here is a control of mine that does this[^]. (It also does some other things – if literally all you want is different coloured text, the owner draw solution that Griff linked to will probably do the job.) It''s not as trivial as it should be.


这是完全有可能的; Bob和Griff提供了很好的解决方案.
我还要补充一点,对于System.Windows.Forms来说,这些要求不是很自然,但是WPF中已经有一些要求,其中列表或树项可以包含任何内容.考虑使用WPF以使用免费内容模型的好处.

请参阅 http://msdn.microsoft.com/en-us/library /bb613548%28v=VS.100%29.aspx [ ^ ].

—SA
This is quite possible; and Bob and Griff provided nice solutions.
I would also add that these requirements are not very natural for System.Windows.Forms, but something that is already available in WPF, where list or tree items can contain any content. Consider switching to WPF to use the benefits of free content model.

See http://msdn.microsoft.com/en-us/library/bb613548%28v=VS.100%29.aspx[^].

—SA


这篇关于列表框中的c#颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆