I have 3 radio buttons all held within a groupbox (so only 1 can be marked at a time). I've got my code working, but to be quicker on updating my label, I want to stop the function from being called twice when a new radioButton is selected.
For instance, in my code below, my default is rb1 and then I click rb2, the rb1 CheckedChanged Event fires and updates the label, then rb2's CheckedChanged Event fires and updates the label again (same value).
What would be the best way to add some extra criteria to where if the label has been updated once, then stop the function from being called again?
CODE:
private void rb1_CheckedChanged(object sender, EventArgs e)
{
if (cmbLetterType.Text.Length != 0)
{
updatePrintedCntLabel();
}
}
private void rb2_CheckedChanged(object sender, EventArgs e)
{
if (cmbLetterType.Text.Length != 0)
{
updatePrintedCntLabel();
}
}
private void rb3_CheckedChanged(object sender, EventArgs e)
{
if (cmbLetterType.Text.Length != 0)
{
updatePrintedCntLabel();
}
}
EDIT: To clarify, this is a C# Winforms application I'm doing this in.
Change your condition to:
Do this for the other 2 handlers as well (using rb2.Checked and rb3.Checked) and each one will only fire when it's the one that's become checked, not unchecked.