CButton changing background color
C / C++ / MFC
3
Posts
2
Posters
0
Views
1
Watching
-
Hi all, I have a form view there I am having checkbox buttons. Now i want to change the background color of the button. I am using OnCtlColor() fn but it is not working.
Try this
// Add a CBrush member variable CBrush m\_brushBK;
In OnInitialUpdate function
m\_brushBK.CreateSolidBrush(RGB(200,200,0));//Set brush color
In the OnCtlColor function
HBRUSH CtestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{if(pWnd->GetDlgCtrlID()==IDC\_CHECK1)// Control ID of the Check box { return m\_brushBK; } else { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); return hbr; }
}
-
Try this
// Add a CBrush member variable CBrush m\_brushBK;
In OnInitialUpdate function
m\_brushBK.CreateSolidBrush(RGB(200,200,0));//Set brush color
In the OnCtlColor function
HBRUSH CtestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{if(pWnd->GetDlgCtrlID()==IDC\_CHECK1)// Control ID of the Check box { return m\_brushBK; } else { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); return hbr; }
}