1. 环境:VS2010

2. 分组

将radio1、radio2、radio3分为1组,radio4、radio5分为另一组;

方法:设置  radio1  的 属性:  group、tabstop、auto均为true

设置  radio2 的 属性: group设为false, tabstop、auto均为true

设置  radio3  的 属性:group设为false,  tabstop、auto均为true


设置  radio4  的 属性:  group、tabstop、auto均为true

设置  radio5  的 属性:  group设为false,tabstop、auto均为true


3.

MFC Radio Button 使用 分组 RadioButton 用法_点击事件


4. 关联int型变量   注意:只需将group属性为true的radio1关联,radio2和radio3无需关联;  同样,radio4需关联,radio5无需关联

MFC Radio Button 使用 分组 RadioButton 用法_头文件_02


5. 第4步完成后,在窗体头文件中可以看到

MFC Radio Button 使用 分组 RadioButton 用法_构造函数_03

构造函数:

MFC Radio Button 使用 分组 RadioButton 用法_点击事件_04

 默认第一个radio被选中,即radio1被选中

6. 事件处理

设置radio1的事件

MFC Radio Button 使用 分组 RadioButton 用法_构造函数_05

设置radio2和radio3的点击事件函数 和 radio1 相同


MFC Radio Button 使用 分组 RadioButton 用法_构造函数_06

事件代码:

MFC Radio Button 使用 分组 RadioButton 用法_头文件_07


注意:updatedata(true) 不能少; 它的作用是 将radio的状态值更新给关联的变量,即m_radiobtngroup1;


MFC Radio Button 使用 分组 RadioButton 用法_点击事件_08

MFC Radio Button 使用 分组 RadioButton 用法_构造函数_09

MFC Radio Button 使用 分组 RadioButton 用法_点击事件_10

感谢关注,欢迎交流!