如何保持listctrl所选行的原始颜色? [英] How do I keep the original color of selected row of listctrl?

查看:139
本文介绍了如何保持listctrl所选行的原始颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我制作了一个ListCtrl,其类型如下:





item1100.mask = LVIF_TEXT;

item1100.pszText = _T();

item1100.iItem = i;

item1100.iImage = 0;

item1100.state = 0;



DWORD dwEXStyle = m_List_1100.GetExtendedStyle();

m_List_1100.SetExtendedStyle(dwEXStyle | LVS_EX_GRIDLINES | | LVS_EX_FULLROWSELECT);





单击一行时,所选行的颜色为深蓝色,但如果单击其他项目在同一个UI中,原始行的颜色从强蓝色变为灰色。



在这种情况下,如何保持ListCtrl所选行的原始颜色? br />


提前谢谢。



我尝试过:



此问题浪费了2天。

Hello,

I have made a ListCtrl with a type of as follows:


item1100.mask = LVIF_TEXT;
item1100.pszText = _T("");
item1100.iItem = i;
item1100.iImage = 0;
item1100.state = 0;

DWORD dwEXStyle = m_List_1100.GetExtendedStyle();
m_List_1100.SetExtendedStyle(dwEXStyle | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );


When I click one row, the color of the selected row is strong blue, but if I click another items within same UI, the color of original row change from strong blue to gray.

In this case, how do I keep the original color of selected row of ListCtrl?

Thank you in advance.

What I have tried:

2 more days wasted for this problem.

推荐答案

这是Windows的默认UI行为。如果列表控件没有焦点,则所选项目将显示为灰色背景。



在这种情况下使用不同颜色的唯一解决方案是使用处理 NM_CUSTOMDRAW(列表视图)通知代码的自定义绘制列表( Windows) [ ^ ]。但是,你必须为该处理程序中的所有可能状态设置颜色并跳过默认图形,因为系统最终会选择所选状态和热门项目。



但是我不会这样做。它会破坏标准的UI行为,您必须获得系统实际使用的颜色所选项目(用户可能选择了不同的主题,其中选择背景颜色不是蓝色)。
This is the default UI behaviour of Windows. If a list control does not has the focus, selected items are shown with a grey background.

The only solution to use a different colour in this case would be using a custom drawn list handling the NM_CUSTOMDRAW (list view) notification code (Windows)[^]. But then you must set the colours for all possible states inside that handler and skip the default drawing because selected and hot items are drawn by the system at last.

But I would not do so. It would break the standard UI behaviour and you would have to get the colours actually used by the system for selected items (the user may have selected a different theme where the selection background colour is not blue).


这篇关于如何保持listctrl所选行的原始颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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