【发布时间】:2019-03-21 13:07:22
【问题描述】:
private void radioButtons_CheckedChanged(object sender, EventArgs e)
{
RadioButton radioButton = sender as RadioButton;
if (radioButton1.Checked) tabControl1.SelectedIndex = 0;
else if (radioButton2.Checked) tabControl1.SelectedIndex = 1;
else if (radioButton3.Checked) tabControl1.SelectedIndex = 2;
else if (radioButton4.Checked) tabControl1.SelectedIndex = 3;
else if (radioButton5.Checked) tabControl1.SelectedIndex = 4;
else if (radioButton6.Checked) tabControl1.SelectedIndex = 5;
else if (radioButton7.Checked) tabControl1.SelectedIndex = 6;
else if (radioButton8.Checked) tabControl1.SelectedIndex = 7;
}
如您所见,我正在使用 EventHandler() 更改带有单选按钮的标签页。我想知道,我怎样才能简化这个“else if”结构。可能我需要一个 foreach(),但我找不到答案。
【问题讨论】:
标签: c# foreach radio-button tabcontrol