VC + + 6.0 use check boxes and radio buttons

Source: Internet
Author: User
Tags function prototype

Radio buttons is used to represent a series of mutually exclusive options, which are often divided into groups, allowing users to select only one option; the check box is the same as the radio button, and the difference is that the check box represents multiple selections, and the user can select one or more options.

Alignment of groups of controls in the Dialog editor

Press the CTRL key and click the individual controls you want to align, and select. The last selected control is the aligned datum, and carefully observed that the 8 small squares around it are solid, while the small squares around the other selected controls are hollow.

Select the both of make Same size in the Layout menu to unify the control dimensions, which are the same size as the datum controls. Select left of Align in the Layout menu to align all the selected controls to the right of the datum controls. Select the down of the align space evenly in the layout menu to make the selected controls equal in vertical spacing.

Use of radio buttons and check boxes

For the sake of illustration, we assume that we created the MFC application based on the dialog box, the project name is Radioandcheckbutton. dialog box resources to add two group boxes, the first group frame ' gender ', there are ' male ', ' female ' two radio buttons; the second group is ' hobby ', which has a ' soccer ' volleyball ' blue ball ' three check boxes, as shown in the following table:

control type Id Title (Caption) Other properties
Group Box Default Gender Default
Radio buttons Idc_sex1 Man Group
Radio buttons Idc_sex2 Woman Default
Group Box Default Hobby Default
check box Idc_hobby1 Football Default
check box Idc_hobby2 Volleyball Default
check box Idc_hobby3 , Basketball Default

To set the tab order for a control

Click the tab Order command under the Layout menu to set the tab ordering of the Control (tab) to ensure that the radio buttons tabs are contiguous.

In the tab order, starting with a control that is true for the Group property (including the control), the end of the control to the next group property is true (excluding the control), and all of these controls will form a group. For radio buttons, only one of the same group can be selected. For radio button controls generated by the Resource Editor, Windows automatically handles the mutex between the same group of controls by default.

Use radio buttons and check boxes specifically

1, call the CButton member function SetCheck set the radio buttons and check box selected state. The member function comes with a parameter of type integer, which is 0 to clear the checked state of the selected button, and a parameter of 1 to set the check state of the selected button. A parameter of 2 indicates that the three-state check box is set to an indeterminate state.

check box TriState property: Creates a three-state check box. In addition to the checked and unchecked states, the three-state check box can also be grayed out. Typically, the dimmed status of a check box indicates that its checked state is indeterminate. In many software installation programs, grayed out often means that only part of the component is selected.

Note that if we call SetCheck in the program to set one of the radio buttons in the same group to be selected, it does not mean that the other radio buttons in the same group is also cleared. Otherwise, it will cause two buttons in the same group to be selected at the same time. This is to be avoided. Therefore, if we change the radio buttons of the selected state through the code, we must remember to clear the selected state of the other radio buttons of the same group at the same time.

2, call the CButton member function Getcheck return the selected state of radio buttons. The function prototype of the function is

int Getcheck () const;

The return value can be 0, 1, and 2, respectively, to represent that the button is unchecked, selected, or intermediate (for the three-state check box).

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.