Use of MFC radio buttons

Source: Internet
Author: User

Add a group of radio buttons to a dialog box
Select the radio button (RadioButton) control in the Toolbox window, and in the dialog box, click where you want to place the control.
Repeat step 1 to add as many radio buttons as you want. Make sure that the tab order for the radio buttons in the group is sequential (for more information, see Changing the tab order of controls).
In the Properties window, set the Group property of the first radio button in the tab order to True. For example
Radio1, Radio2, Radio3 as a group, Radio4, Radio5 as a group
Set Radio1 property: Group,tabstop,auto
Set Radio2 property: Tabstop,auto
Set Radio3 property: Tabstop,auto
Set Radio4 property: Group,tabstop,auto
Set Radio5 property: Tabstop,auto

VC2008 MFC Create radio button Group get radio button group values-it heart snow-NET START here Instructions:
Only the first radio button in the group can set the Group property to True. If there are other controls that do not belong to a group of buttons, set the group property of the first control outside the set to true. You can quickly determine the first control outside a group by pressing Ctrl + D to view the Tab order.

How to initialize a radio button, which is the default one radio button
Initializes the first radio selection, which is the first radio button by default

In this function Clotterydlg::oninitdialog ()
CButton *PB;
pb= (cbutton*) GetDlgItem (IDC_RADIO1);
Pb->setcheck (TRUE);


To determine which radio box is selected:

Using the Group box control, this group box is not a combo box, the group box is to circle multiple radio buttons, and then the Group property of the button that you want to set as the default button is selected, and the group properties of the other buttons are canceled.
So these radio buttons become a group can be implemented in between them to choose, these 3 buttons only group properties can map a variable, add a variable radioselect, its type is int, this radioselect variable can be used to return the user chose which option, 0 means that the first radio button is selected, 1 means that the second radio button is selected, and 2 means that a third radio button is selected
Switch (radioselect)
{
Case 0:
:: AfxMessageBox ("Check First");
Case 1:
:: AfxMessageBox ("Check 2nd");
Case 2:
:: AfxMessageBox ("Check 3rd");
}

Here's the second method:

The single box that is divided into a group is mutually exclusive, and the single box in the group does not affect each other (only one of the boxes in the group box is selected)
VC Create a dialog-based class, add a group box to the dialog control, and place three radio boxes in the group box with IDs Idc_radio1,idc_radio2,idc_radio3. You can add a button control to a dialog box control, The button control clicks the command response to add the following code:
UINT Nsex=getcheckedradiobutton (Idc_radio1,idc_radio3);//parameter is the ID number of the first and last radio box, respectively
Switch (nsex)
{
Case IDC_RADIO1:
:: AfxMessageBox ("Check First");
Case Idc_radio2:
:: AfxMessageBox ("Check 2nd");
Case IDC_RADIO3:
:: AfxMessageBox ("Check 3rd");
}

Use of MFC radio buttons

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.