VC study Note 5: Use of the single-choice button control (ridio button)
1. Group Single-choice buttons:
Set attributes for the first single-choice button in each group: group, tabstop, and auto. Set attributes for other buttons: tabstop and auto.
For example:
Ridio1, ridio2, and ridio3 are a group, and ridio4 and ridio5 are a group.
Set ridio1 attributes: group, tabstop, auto
Set the ridio2 attribute: tabstop, auto
Set the ridio3 attribute: tabstop, auto
Set ridio4 attributes: group, tabstop, auto
Set the ridio5 attribute: tabstop, auto
Ii. Use classwizard to define a single-choice controlValue variable, Each group can only define one. For example, m_iridio1 and m_iridio4.
3. assign values to m_iridio1, 0 1st; 1 second; 2 third; value appended updatedata (false)
M_iridio1 = 2;
Updatedata (false );
Select the third button.
4. Use classwizard to generate the click message function of each radio button and add the following content:
Void cweditview: onradio1 ()
{
M_iridio1 = 0; // The first radio button is selected.
}
Void cweditview: onradio2 ()
{
M_iridio1 = 1; // The second radio button is selected.
}
Void cweditview: onradio3 ()
{
M_iridio1 = 2; // The third radio button is selected.
}
Void cweditview: onradio4 ()
{
M_iridio4 = 0; // The fourth radio button is selected.
}
Void cweditview: onradio5 ()
{
M_iridio4 = 1; // The fifth radio button is selected.
}
======================================
In step 3, set the default button in oninitdialog to be more flexible.
4. Set the default button:
When defining a control variable, classwizard sets the initial value of the variable to-1 in the constructor. You only need to change it to another value.
For example:
// {Afx_data_init (cweditview)
M_ridio1 = 0; // The first radio button is selected at the beginning.
M_ridio4 = 0; // The fourth radio button is selected in the initial stage.
//} Afx_data_init
References