MFC RadioButton分組用法

1.Radio1、Radio2、Radio3分爲一組;

  Radio4、Radio5、Radio6分爲另一組;

設置Radio1 的屬性: group、tabstop、auto均爲true
設置Radio2、Radio3的屬性: group設爲false, tabstop、auto均爲true

設置Radio4 的屬性: group、tabstop、auto均爲true
設置Radio5、Radio6的屬性: group設爲false, tabstop、auto均爲true

2.按CTRL+D,保證同一組內的radio的tab序號是連續的;調整tab序號的方式是:鼠標依次點擊數字

 

3.關聯int型變量

只需將group屬性爲true的Radio1關聯,Radio2和Radio3無需關聯;同樣,Radio4需關聯,Radio5和Radio6無需關聯

 

 

 4.設置完可以看到頭文件以下變量

 

 

 

 5.設置事件

 設置Radio1的事件

 

 設置Radio2和Radio3的點擊事件函數 和 Radio1 相同

 

 Updatedata(true) 不能少; 它的作用是 將radio的狀態值更新給關聯的變量

void CMFCApplication4Dlg::OnBnClickedRadio1()
{
    // TODO: 在此添加控件通知處理程序代碼
    UpdateData(true);
    switch (m_RadioGroup1)
    {
        case 0:
            MessageBox(_T("Radio1 clicked!"));
            break;
        case 1:
            MessageBox(_T("Radio2 clicked!"));
            break;
        case 2:
            MessageBox(_T("Radio3 clicked!"));
            break;
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章