VS2005 RadioButton的使用
1. 共有IDC_RADIO1、IDC_RADIO2、IDC_RADIO3、IDC_RADIO4四个Button;想把前两个分到一组,后两个分到一组;方法:
把IDC_RADIO1的Group propety设为true,把IDC_RADIO2的Group propety设为false;
把IDC_RADIO3的Group propety设为true,把IDC_RADIO4的Group propety设为false。
这样每组中每次只能有一个button被选中。
2. 获取到被选中的button,方法:
GetCheckedRadioButton(IDC_RADIO1, IDC_RADIO2)==IDC_RADIO1 IDC_RADIO1被选中;
GetCheckedRadioButton(IDC_RADIO3, IDC_RADIO4)==IDC_RADIO4 IDC_RADIO4被选中;
VS2012 RadioButton的使用
XAML如下
<StackPanel> <RadioButton GroupName="colorgrp">Red</RadioButton> <RadioButton GroupName="colorgrp">Blue</RadioButton> <RadioButton GroupName="numgrp">1</RadioButton> <RadioButton GroupName="numgrp">2</RadioButton> <RadioButton>4</RadioButton> <RadioButton>5</RadioButton> </StackPanel>
在一个Panel下,若没有指定GroupName则为一组,指定了GroupName为另外一组.
逻辑:一组内,选中一个Button取消其他的Button选中状态.