我在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回到原来正确的分组
为了让控件居中,我将四个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回到原来正确的分组
已经设置了,但是置groupbox为父后就乱掉了
// 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
}