Reputation: 121
I have created a MFC form with 4 radio buttons, with names A, B, X,Y on the form,
Now I want the form to display the names X, Y when I select the button A
and when I select the button B, I want the names of X, Y to change to M, N
How to do that?
Upvotes: 1
Views: 1639
Reputation: 10411
You change the text on radiobutton the way you change the on any other control, using SetWindowText();
In order to handle the events of "selecting" the radiobuttons, add a handler for BN_CLICKED notification message. I recommend you use the same handler for all your four radiobuttons. Then, inside the function write this small code:
// assumptions:
// there are four radiobuttons: IDC_RADIOA, IDC_RADIOB, IDC_RADIOX, IDC_RADIOY
// The message map
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
ON_BN_CLICKED(IDC_RADIOA, OnRadio)
ON_BN_CLICKED(IDC_RADIOB, OnRadio)
ON_BN_CLICKED(IDC_RADIOX, OnRadio)
ON_BN_CLICKED(IDC_RADIOY, OnRadio)
END_MESSAGE_MAP()
// a common handler for all four radiobuttons
void CMyDlg::OnRadio()
{
switch(GetCheckedRadioButton(IDC_RADIOA, IDC_RADIOY))
{
case IDC_RADIOA:
SetDlgItemText(IDC_RADIOX, _T("X"));
SetDlgItemText(IDC_RADIOY, _T("Y"));
break;
case IDC_RADIOB:
SetDlgItemText(IDC_RADIOX, _T("M"));
SetDlgItemText(IDC_RADIOY, _T("N"));
break;
default:
// you have not specified what to do when you select radio X and Y, so specify it here
break;
}
}
Upvotes: 3