Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
iam using list control in mfc . pls help to change the color of list control of view record?<

What I have tried:

i tried to change the color of the list control.but the outside color only changed.
C++
BOOL Tag::OnEraseBkgnd(CDC* pDC)
{
	CRect r;
	GetClientRect(&r);
	CBrush br(RGB(0, 100, 0));
	pDC->SelectObject(br);
	pDC->FillRect(r, &br);
	return TRUE;
}

HBRUSH Tag::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	CBrush br(RGB(0, 255, 0));
	return (HBRUSH)br;
}
Posted
Updated 12-Mar-17 17:16pm
v3

1 solution

To set the color for all items use SetTextColor and SetBkColor [EDIT], and SetTextBkColor[/EDIT].

If you want to set the colour for individual items, you have to handle the NM_CUSTOMDRAW notification: Neat Stuff to Do in List Controls Using Custom Draw[^]
 
Share this answer
 
v2
Comments
Anoha 9-Mar-17 23:03pm    
i used SetBKColor color. but the background color inside the list control is not changing.
Jochen Arndt 10-Mar-17 3:19am    
Sorry, I forgot that there is the function SetTextBkColor() which sets the colour for used items while SetBkColor() is only for unused items.
I will update my answer.

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