如何在MFC应用程序的ListControl(ListView)中插入彩色文本? [英] How to insert colored text into a ListControl (ListView) in an MFC application?

查看:93
本文介绍了如何在MFC应用程序的ListControl(ListView)中插入彩色文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我有3列的ListControl.在第三列中只能有两个文本值(确定"或失败").我想根据结果为文本着色.如果正常,则应为绿色,如果失败,则应为红色.我知道我必须使用NM_CUSTOMDRAW,但我无法弄清楚如何正确使用它(我可以为整列或整行着色,但这不是我想要的颜色),而我没有都找不到解决方案.

有人可以给我一个有用的解决方案吗?

提前谢谢!

kampi

Hi!

I have a ListControl with 3 columns. In the third column can be only two text value (OK or FAILED). I want to color this text according to that what is the result. If it is OK then it should be green and if it is FAILED then it should be red. I know i have to use NM_CUSTOMDRAW but i can''t figure it out how to use it correctly (i can color the whole column or the whole line, but this isn''t what i want), and i didn''t find a solution neither.

Can someone please give me a useable solution?

Thanks in advance!

kampi

推荐答案

您可能需要所有者绘制控件,然后以所需的各种颜色绘制文本.我肯定会在CP上找到有关如何执行此操作的文章.

您的标签有误,如果仅使用C,就不能使用MFC.
You may need to owner draw the control and then draw your text in the various colors you want. I''d feel sure there are articles on CP on how to do this.

Your tags are wrong, you can''t use MFC if you''re only using C.


对不起,克里斯蒂安!我输错了.我的意思是C ++.现在可以吗?我在所有可用的代码中进行搜索,但是没有找到.我发现只有每第二行或第三列或第四行被着色的代码.所有代码都使用了prepaint,这对我不利,因为在开始时,第三列为空.我据此粘贴了文本,如果复制(这就是我在做的)是否成功,则我不能使用这些代码.

kampi
Sorry Christian! I misstyped. I meant C++. Is it ok now? I searched everywhere i useable code, but i didn''t found. I found only codes where every second line, or the third column, or the fourth line was colored. All code used prepaint, which isn''t good for me, because, at the beginning the third column is empty. I paste the text, according to that, if the copy(that''s what i''m doing) was succesfull or not, and so i can''t use those codes.

kampi


you can use NM_CUSTOMDRAW and get the specific row and column.
NMLVCUSTOMDRAW* lplvcd = (NMLVCUSTOMDRAW*)pNMHDR;
*pResult = CDRF_DODEFAULT ;
int iRow = lplvcd->nmcd.dwItemSpec;
int iCol = lplvcd->iSubItem;

if it is the row and column of the desired text, write the code to set the colour using
lplvcd->clrText = RGB value; 


这篇关于如何在MFC应用程序的ListControl(ListView)中插入彩色文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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