Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi ,
1. im doing a program to change the colour of push button,edit,check box by choosing the colour from combo box by clicking push button. My problem is the push button colour is not changing ,, please help me to change the colour of the push button


2. if the push button is clicked without choosing the colour from the combo box,, a message must appear as "select a color".

3.how to change the colour of check box[the white area inside the check box]

I searched for the code but i didnt get it,, it will be helpfull if you give me the codes
thank you

this is my code
void CComboTestDlg::OnButton1()
{
	int index = m_ColorCombo.GetCurSel();
	if(index != CB_ERR)
	{
		m_brush.DeleteObject();
		switch(index)
		{
		case 0:
		m_brush.CreateSolidBrush(RGB(0, 240, 120));
		break;
		case 1:
		m_brush.CreateSolidBrush(RGB(128, 0, 240));
		break;
		case 2:
		m_brush.CreateSolidBrush(RGB(0, 128, 0));
		break;
		case 3:
		m_brush.CreateSolidBrush(RGB(128, 128, 0));
		break;
		case 4:
		m_brush.CreateSolidBrush(RGB(0, 0, 128));
		break;
		default:
			m_brush.CreateSolidBrush(::GetSysColor(COLOR_WINDOWTEXT));
			break;
		}
		Invalidate(TRUE);

	}
	else
		{
		AfxMessageBox("Select a color  ");
		}
	
}

HBRUSH CComboTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
switch ( nCtlColor )
{
case CTLCOLOR_EDIT:
case CTLCOLOR_MSGBOX:
case CTLCOLOR_BTN:
case CTLCOLOR_STATIC:
pDC->SetTextColor(RGB(0, 240, 120));

pDC->SetBkColor(RGB(0, 0, 0));
return (HBRUSH)(m_brush.GetSafeHandle());
case CTLCOLOR_DLG:
return static_cast<HBRUSH> ( m_brush.GetSafeHandle() );
}
// TODO: Return a different brush if the default is not desired

}

thank you in advance
AJ
Posted
Updated 17-Mar-11 18:55pm
v4

1 solution

You have to paint those kinds of controls yourself. The usual way to do this is to create a new class derived from CButton (or CCheckbox), and override the OnPaint command. Don't forget that you have to also paint for ALL states the control can have.

There's probably already code out there to do edxactly what you want (and most likely right here on CodeProject). Google is your friend.
 
Share this 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