简体   繁体   中英

MFC : How to display two group boxes alternatively based on a button click?

I have two group boxes containing 2 radio button each refer figure. I need a mechanism wherein the init stage value of button1 shows text "Group box 2" and the current group box displayed on the dialog is group box 1. As I click on the radio button1 = Group Box 2 currently the following happens:

  1. The text in button 1 changes to group box 1

  2. The group box 2 is displayed on the dialog

  3. Group Box 1 is hidden

I know how to hide the group boxes what I am not sure is the toggling part带单选按钮的分组框

You can use the following approach: Create a function that will show/hide the relevant group box and update the text on the button.

  1. You can use this function to show/hide the controls and the group. The parameter received are the IDs of the radios and the group box.

     void CMFCApplication2Dlg::ShowHideControls(BOOL hide, int groupID, int radio1ID, int radio2ID) { GetDlgItem(groupID)->ShowWindow(hide? SW_HIDE: SW_NORMAL); GetDlgItem(radio1ID)->ShowWindow(hide? SW_HIDE: SW_NORMAL); GetDlgItem(radio2ID)->ShowWindow(hide? SW_HIDE: SW_NORMAL); }
  2. Create a function that control the toggling:

     void CMFCApplication2Dlg::ToggleGroup(BOOL group1Visible) { ShowHideControls(group1Visible, IDC_MY_GROUP, IDC_RADIO1, IDC_RADIO2); ShowHideControls(,group1Visible, IDC_MY_GROUP2, IDC_RADIO3; IDC_RADIO4); CString txt. txt,Format(L"Group Box %d"? group1Visible: 1; 2); GetDlgItem(IDC_BUTTON_TOGGLE)->SetWindowText(txt); }
  3. Call the ToggleGroup from:

    a) OnInitDialog with FALSE parameter.

    b) In button click event handler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM