Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi ,
Im doing a program for changing the colour of controls selected from the combo box. my doubt is , when push button is clicked without selecting a colour from combo a message must appear " select a colour". im not getting the pop up message,,,if i get the pop up message the control colour is not changing, I dono wat mistake i had done .pls correct me ,,,
My coding
C#
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 colour");
        }
}

thank you
Posted
Updated 22-Mar-11 17:59pm
v6
Comments
Wendelius 21-Mar-11 9:11am    
Pre tags corrected
CPallini 21-Mar-11 9:14am    
What misbehaviour are you experiencing? At first look your code looks correct.
degorio 21-Mar-11 9:22am    
when button is selected without choosing the color from combo the message is not appearing
CPallini 21-Mar-11 9:32am    
Why don't you use the debugger to see the value of 'index'?
(Alternatively you may TRACE it or use a MessageBox).
degorio 21-Mar-11 9:35am    
im new to MFC.. i dono how to do it,, can you guide me

1 solution

 
Share this answer
 
Comments
degorio 21-Mar-11 9:25am    
i need MFC coding
CPallini 21-Mar-11 9:34am    
What has it to do with OP request? Did you miss the C++/MFC tag?

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