我有一组 8 个单选按钮,有没有一种简单的方法来检查该组的“选中”状态是否已更改?我不需要知道哪个按钮已被选中,只需知道是否已选中另一个按钮即可。有点像整个组的 CheckedChanged 事件。
您可以将相同的CheckedChanged事件处理程序分配给所有单选按钮。当您选中一个单选按钮时,该方法将被调用两次(对于失去复选标记的单选按钮和被选中的单选按钮)。因此,仅处理选中的事件。
private void anyRadioButton_CheckedChanged(object sender, EventArgs e)
{
// The radio button that raised the event
var radioButton = sender as RadioButton;
// Only do something when the event was raised by the radiobutton
// being checked, so we don't do this twice.
if(radioButton.Checked)
{
// Do something here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2275 次 |
| 最近记录: |