他の答えは正しいですが、根本的な問題の理由を見逃しています。ラジオ ボタンがチェックされている場合、送信される最初のイベントはチェックされていないアイテムからの変更ですが、コントロール名で状態をチェックすると、フォームがまだ更新されていないため、古いチェック ステータスが表示されます。その真のステータスを確認するには、sender オブジェクトをキャストする必要があります。これにより、必要に応じて、選択解除されている条件に関連するアクションを実行できます。
以下の珍しいシナリオでは、複数のラジオ ボタンが同じハンドラ イベントに送信されます。押されたラジオボタンに応じて異なるアクションを実行する必要があるため、チェック済みの送信者の状態をチェックするだけでは機能しません。そのため、最初にチェックを外したばかりの送信者を無視します。次に、チェックされた送信者をコントロール名で識別して、正しいアクションを処理します。
private void ModeChangedExample(object sender, EventArgs e)
{
// multiple radio buttons come here
// We only want to process the checked item.
// if you need to something based on the item which was just unchecked don't use this technique.
// The state of the sender has not been updated yet in the form.
// so checking against rdo_A check state will still show it as checked even if it has just been unchecked
// only the sender variable is up to date at this point.
// To prevent processing the item which has just been uncheked
RadioButton RD = sender as RadioButton;
if (RD.Checked == false) return;
if (rdo_A.Name == RD.Name)
{
//Do stuff
}
if (rdo_B..Name == RD.Name)
{
// Do other stuff
}
if (rdo_C.Name == RD.Name)
{
// Do something else
}
}