Because you've set Checked = false in return of the dialogresult? Hence, toggling the state again?
EDIT: Of note, you are probably using the CheckStateChanged event. So, you check the checkbox (setting it to true), it fires, you show the MessageBox, you set the checkbox back to false, which in turn, causes the event to fire again (you are changing the state).
This is where you could use the Click event, as opposed to setting a flag (proposed solution). That way when you set the checkbox back to false, in code, the Click event won't fire. At runtime, a Click event, for a checkbox, will always toggle the checkbox on/off, no matter where you click on the checkbox.
In conclusion, just use the Click event:
private void rChkBoxB_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(rTxtBoxFormatID.Text) > 256)
{
DialogResult dialogresult = MessageBox.Show("B does not support numbering over a number!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
if (dialogresult == DialogResult.OK)
{
rChkBoxB.Checked = false;
}
}
}
Of course, in either version of your code, I'm assuming you want to actually check if Text > 256 when you are checking it to true. So you might want to:
private void rChkBoxB_Click(object sender, EventArgs e)
{
if (rChkBoxB.Checked == false) return; // NEW CODE HERE
if (Convert.ToInt32(rTxtBoxFormatID.Text) > 256)
{
DialogResult dialogresult = MessageBox.Show("B does not support numbering over a number!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
if (dialogresult == DialogResult.OK)
{
rChkBoxB.Checked = false;
}
}
}