mfc 怎么设置 radio控件 使得只能选中其中一个
在 MFC 中,可以使用 CButton 类的 SetCheck 方法来设置 RadioButton 控件的选中状态。可以将要设置为选中的 RadioButton 控件的标识符作为参数传递给 SetCheck 方法,将其设置为 BST_CHECKED(选中状态),将其他 RadioButton 控件设置为 BST_UNCHECKED(未选中状态)。
以下是一个示例代码,演示如何设置 RadioButton 控件使得只能选中其中一个:
// 假设有三个 RadioButton 控件的 ID 分别为 IDC_RADIO1、IDC_RADIO2 和 IDC_RADIO3
// 首先获取 RadioButton 控件的指针
CButton* pRadio1 = (CButton*)GetDlgItem(IDC_RADIO1);
CButton* pRadio2 = (CButton*)GetDlgItem(IDC_RADIO2);
CButton* pRadio3 = (CButton*)GetDlgItem(IDC_RADIO3);
// 然后将其中一个 RadioButton 设置为选中状态,其他设置为未选中状态
pRadio1->SetCheck(BST_CHECKED);
pRadio2->SetCheck(BST_UNCHECKED);
pRadio3->SetCheck(BST_UNCHECKED);
在上述示例代码中,假设 IDC_RADIO1 的 RadioButton 控件将被设置为选中状态,而 IDC_RADIO2 和 IDC_RADIO3 的 RadioButton 控件将被设置为未选中状态。根据实际情况,您可以根据需要设置不同的 RadioButton 控件
原文地址: http://www.cveoy.top/t/topic/hC5x 著作权归作者所有。请勿转载和采集!