Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am loading strings to ccombobox and i also want to change the dropdown background color of it.

dc->FillSolidRect(&rc, CustomColor);

I have added this code to overriding OnDrawItem method

It fills entire drop down with the custom color but the text previously added to combobox will not be shown.

How to make text visible after filling the combobox background color
Posted

1 solution

Instead of overriding OnDrawItem you need to override OnCtlColor like this:

C++
HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    if (nCtlColor == CTLCOLOR_LISTBOX)
        pDC->SetBkColor(RGB(255, 0, 0));

    return CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
}
 
Share this answer
 
v2
Comments
yash35 28-Sep-15 13:14pm    
hmm.... i tried modifying to OnCtlColor. The method is firing but changes are not reflecting to the UI. Is any additional code required here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900