Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals
19.1.2..Creating Radio Buttons......................................................................
Because they come in a group, to create radio buttons, on the Controls toolbox, click the
Radio Button button and click the desired area on the host window. In the same
way, add one or more radio buttons:
To indicate that the radio buttons belong to a group, you should (with emphasis) place
them inside of a frame, the most common of which is the Group Box control.
Alternatively, you can add them to a Picture frame (other allowed but unlikely frames are
a Static control or an Animation box):
The main advantage of a Group Box control, which explains why it is the most common
container of radio buttons, is that it inherently provides a caption you can use to indicate
what its set of radio buttons is used for.
Two properties are of particular importance to both you and the user: the label and the
state of the control. The label is text that specifies what a particular radio button is used
for. The label should be explicit enough for the user to figure out the role of an item in
the group.
To change the label of a radio button, after adding the control, replace the value of the
Caption field in the Properties window. If the control exists already, to change its
caption, call the CWnd::SetWindowText() method.
Pratical Learning: Creating Radio Buttons
- From the Controls toolbox, click the Group Box button and click on the upper
left section of the dialog box. - Change its Caption to Flavor
- From the Controls toolbox, click the Radio Button and click inside the Flavor
group box