简体   繁体   中英

MFC change CListCtrl background color

I am trying to develop a MFC application. I have a CListCtrl object and I want to change it's background color complately. I tried to make it in HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) event. But this event isn't fired for CListCtrl object. So How can I do it. Thanks in advanced.

You may use CListCtrl::SetBkColor.

For list views you also can use owner draw (DrawItem) or custom draw.

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. Part I , Part II

According to the MSDN documentation, you can invoke the CListCtrl::SetBkColor method to set the background color of a 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.

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(...)); it will be working..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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