MFC单选按钮 [英] MFC Radio Button
问题描述
在MFC对话框中,我在一个组框中有3个单选按钮
In MFC dialog, I have 3 radio buttons in a group box
#define IDC_RADIO1                     1001
#define IDC_RADIO2                     1005
#define IDC_RADIO3                     1008
#define IDC_RADIO1 1001
#define IDC_RADIO2 1005
#define IDC_RADIO3 1008
对于IDC_RADIO1,group属性设置为true。
The group property is set true for IDC_RADIO1.
CButton m_radio1;
CButton m_radio2;
CButton m_radio3;
CButton m_radio1;
CButton m_radio2;
CButton m_radio3;
如果我打电话,
If I call,
m_radio1.SetCheck( true);
$
m_radio2.SetCheck(true);
m_radio1.SetCheck(true);
m_radio2.SetCheck(true);
为什么单选按钮1和2是 被选中。为什么在拨打电话时没有取消选择单选按钮1 m_radio2.SetCheck(true);。
why radio button 1 and 2 are getting selected. why radio button 1 is not getting deselected when calling m_radio2.SetCheck(true);.
提前致谢。
推荐答案
当用户点击单选按钮时,您希望的行为通过用户界面进行。 BS_AUTORADIOBUTTION样式的文档说 - "创建一个与单选按钮相同的按钮,除了当用户选择它时,系统会自动
设置按钮的检查状态以进行检查并自动设置检查清除同一组中所有其他按钮的状态。"
The behavior you desire happens through the UI when a radio button is clicked by a user. The docs for the BS_AUTORADIOBUTTION style say -- "Creates a button that is the same as a radio button, except that when the user selects it, the system automatically sets the button's check state to checked and automatically sets the check state for all other buttons in the same group to cleared."
如果要通过代码实现相同的操作,请使用对话框
CheckRadioButton功能
If you want to achieve the same thing through code use the dialog's CheckRadioButton function
这篇关于MFC单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!