我在groupbox中插入了四个radiobutton,将radio1和radio3的group属性选中。
为了让控件居中,我将四个radiobutton置父为groupbox,然后将groupbox居中。
本应该是radio1和2为一组,radio3和4为一组。居中后分组发生混乱,如图
代码如下:       CRect gp_rc,rd1_rc,rd2_rc,rd3_rc,rd4_rc; m_gp.GetWindowRect(gp_rc); m_rd1.GetWindowRect(rd1_rc);
GetDlgItem(IDC_RADIO2)->GetWindowRect(rd2_rc);
        m_rd3.GetWindowRect(rd3_rc);
GetDlgItem(IDC_RADIO4)->GetWindowRect(rd4_rc); m_rd1.MoveWindow(rd1_rc.left-gp_rc.left,rd1_rc.top-gp_rc.top,
             rd1_rc.Width(),rd1_rc.Height(),1);
GetDlgItem(IDC_RADIO2)->MoveWindow(rd2_rc.left-gp_rc.left,rd2_rc.top-gp_rc.top,
             rd2_rc.Width(),rd2_rc.Height(),1);
m_rd3.MoveWindow(rd3_rc.left-gp_rc.left,rd3_rc.top-gp_rc.top,
             rd3_rc.Width(),rd3_rc.Height(),1);
GetDlgItem(IDC_RADIO4)->MoveWindow(rd4_rc.left-gp_rc.left,rd4_rc.top-gp_rc.top,
             rd4_rc.Width(),rd4_rc.Height(),1);
m_rd1.SetParent(GetDlgItem(IDC_GROUP));
GetDlgItem(IDC_RADIO2)->SetParent(GetDlgItem(IDC_GROUP));
m_rd3.SetParent(GetDlgItem(IDC_GROUP));
GetDlgItem(IDC_RADIO4)->SetParent(GetDlgItem(IDC_GROUP));
    
m_gp.CenterWindow();
求教如何再让radiobutton回到原来正确的分组

解决方案 »

  1.   

    在资源编辑界面下 Ctrl+D 重新修改下控件顺序,   一组的按Group, Radio2 Radio3 …… RadioN 的顺序编排
      

  2.   

    1,3上设置Group为True
      

  3.   


    已经设置了,但是置groupbox为父后就乱掉了
      

  4.   

    求教  radio button可以用代码动态分组吗~
      

  5.   

    最好 分成 2个 GroupBox ,设置 GroupBox 的 标题,以区分不同功能
      

  6.   

    我再用两个groupbox并且将12分在一组,34分在一组后,也将这两个groupbox居中了,然后radiobutton还是没法回到原来的分组,是不是手动置父以后排序混乱了呢?
      

  7.   

    实际程序控件太多,想一次性居中很多控件,就将包含这些控件的groupbox置为父窗口,然后居中
      

  8.   

    我只看到你把 2、4 的父窗口设置为 GroupBox 了,而 1、3 则没有,那么相当于 1、3 的父窗口还是对话框。RadioButton 要分组的话,至少要做到:⒈同一分组的所有控件必须是同一个窗口的子窗口;⒉分组的第一个窗口拥有 WS_GROUP 样式,从该控件 ID 开始,按照窗口的 Z 序,直到下一个拥有 WS_GROUP 之前的窗口都将属于该分组。这些常识我想很多人都知道。
      

  9.   

    这个办法不好, radio成了 Group 的 子窗口, 响应函数有问题。
      

  10.   

    如果一定要这样, 要先 Center   Group 控件,再move, 不要 setParent:。
    // TODO: Add extra initialization here
        m_gp.CenterWindow();
    //
        CRect gp_rc,rd1_rc,rd2_rc,rd3_rc,rd4_rc;
    //
        m_gp.GetWindowRect(gp_rc);
    afxDump << gp_rc << "\n";// (L 52, T 153, R 358, B 297)
    // rd1
        m_rd1.GetWindowRect(rd1_rc);//
    afxDump << rd1_rc << "\n";// 
        m_rd1.MoveWindow(gp_rc.left+5,gp_rc.top+5,rd1_rc.Width(),rd1_rc.Height());
    // rd2
        GetDlgItem(IDC_RADIO2)->GetWindowRect(rd2_rc);
        GetDlgItem(IDC_RADIO2)->MoveWindow(gp_rc.left+120,gp_rc.top+5,rd2_rc.Width(),rd2_rc.Height());
    // rd3
        m_rd3.GetWindowRect(rd3_rc);//
    afxDump << rd3_rc << "\n";// 
        m_rd3.MoveWindow(gp_rc.left+5,gp_rc.top+45,rd3_rc.Width(),rd3_rc.Height());
    // rd4
        GetDlgItem(IDC_RADIO4)->GetWindowRect(rd4_rc);
        GetDlgItem(IDC_RADIO4)->MoveWindow(gp_rc.left+120,gp_rc.top+45,rd4_rc.Width(),rd4_rc.Height());
    //
    return TRUE;  // return TRUE  unless you set the focus to a control
    }