I'm trying to alternate if a button is checked. I've come up with this, which works but its feels unnecessary to write 70 lines of code for such a simple task.
How would I go about to shorten this up, is there any way I can call the base toolStripButton
and tell it to uncheck other buttons when clicked on and check it self?
private void toolStripButton1_Click(object sender, EventArgs e)
{
if (toolStripButton1.Checked == true)
{
toolStripButton2.Checked = false;
toolStripButton3.Checked = false;
toolStripButton4.Checked = false;
toolStripButton5.Checked = false;
toolStripButton6.Checked = false;
}
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
if (toolStripButton2.Checked == true)
{
toolStripButton1.Checked = false;
toolStripButton3.Checked = false;
toolStripButton4.Checked = false;
toolStripButton5.Checked = false;
toolStripButton6.Checked = false;
}
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
if (toolStripButton3.Checked == true)
{
toolStripButton1.Checked = false;
toolStripButton2.Checked = false;
toolStripButton4.Checked = false;
toolStripButton5.Checked = false;
toolStripButton6.Checked = false;
}
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
if (toolStripButton4.Checked == true)
{
toolStripButton2.Checked = false;
toolStripButton3.Checked = false;
toolStripButton1.Checked = false;
toolStripButton5.Checked = false;
toolStripButton6.Checked = false;
}
}
private void toolStripButton5_Click(object sender, EventArgs e)
{
if (toolStripButton5.Checked == true)
{
toolStripButton2.Checked = false;
toolStripButton3.Checked = false;
toolStripButton1.Checked = false;
toolStripButton4.Checked = false;
toolStripButton6.Checked = false;
}
}
private void toolStripButton6_Click(object sender, EventArgs e)
{
if (toolStripButton6.Checked == true)
{
toolStripButton2.Checked = false;
toolStripButton3.Checked = false;
toolStripButton1.Checked = false;
toolStripButton5.Checked = false;
toolStripButton4.Checked = false;
}
}
foreach
thusly:nextButton.Checked(nextButton.Equals(sendingButton))
\$\endgroup\$