简体   繁体   English

MFC更改CListCtrl背景颜色

[英]MFC change CListCtrl background color

I am trying to develop a MFC application. 我正在尝试开发一个MFC应用程序。 I have a CListCtrl object and I want to change it's background color complately. 我有一个CListCtrl对象,我想要整齐地改变它的背景颜色。 I tried to make it in HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) event. 我试图在HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)事件中制作它。 But this event isn't fired for CListCtrl object. 但是,对于CListCtrl对象,不会触发此事件。 So How can I do it. 那我怎么能这样做呢。 Thanks in advanced. 提前致谢。

You may use CListCtrl::SetBkColor. 您可以使用CListCtrl :: SetBkColor。

For list views you also can use owner draw (DrawItem) or custom draw. 对于列表视图,您还可以使用所有者绘制(DrawItem)或自定义绘制。

Custom draw is the easiest way for getting more control over the background. 自定义绘制是获得对背景的更多控制的最简单方法。 Setting the colors only is really simple. 仅设置颜色非常简单。

In CodeGuru you find a good class and description that simplifies the use of custom draw. 在CodeGuru中,您可以找到一个简单的类和描述,简化了自定义绘制的使用。 Part I , Part II 第一部分第二部分

According to the MSDN documentation, you can invoke the CListCtrl::SetBkColor method to set the background color of a CListCtrl . 根据MSDN文档,您可以调用CListCtrl::SetBkColor方法来设置CListCtrl的背景颜色。

For finer grained control, you may want to read this CodeProject article , that shows how to use the custom draw feature of the listview control to draw rows with alternate colors. 对于更精细的控制,您可能需要阅读此CodeProject文章 ,该文章显示了如何使用listview控件的自定义绘制功能来绘制具有替代颜色的行。

you can set the properties in Owner Draw true for background color of any control property enter image description here then using OnCtlColor method or Using setBkColor(RGB(...)); 你可以在Owner Draw中设置属性true为任何控件属性的背景颜色输入图像描述然后使用OnCtlColor方法或使用setBkColor(RGB(...)); it will be working.. 它会工作..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM