J
John Salerno
Ok, I'm just messing around with a little project based on a computer
game I'm playing, which should explain some of the references in the
code. My problem is, when I click "OK" in the message box, my computer
beeps again and the message box remains (which I assume means it is
appearing a second time). After I click OK again, it goes away. Why is this?
Also, any advice on how to further generalize the code in the event
handler would be appreciated. At first, I had all the checking in the
event handler, then I realized I should probably write my own method to
check. Basically what I want is if you click the word "Barbarian" while
one of three particular other radio buttons is clicked, I want the
message to appear. At first I had the alignment clear itself, but then I
figured it made more sense to clear the "Barbarian" radio button, since
that's what is being clicked in the first place.
public partial class frmCharacterManager : Form
{
private string incompatibleSelection = "Incompatible Selection";
public frmCharacterManager()
{
InitializeComponent();
}
private void rdoBarbarian_CheckedChanged(object sender,
EventArgs e)
{
string barbarianMessage = "The Barbarian class is
restricted to nonlawful alignments.";
if (CheckLawfulAlignment())
{
rdoBarbarian.Checked = false;
MessageBox.Show(barbarianMessage, incompatibleSelection);
}
}
public bool CheckLawfulAlignment()
{
if (rdoLawfulGood.Checked == true ||
rdoLawfulNeutral.Checked == true || rdoLawfulEvil.Checked == true)
return true;
else
return false;
}
}
game I'm playing, which should explain some of the references in the
code. My problem is, when I click "OK" in the message box, my computer
beeps again and the message box remains (which I assume means it is
appearing a second time). After I click OK again, it goes away. Why is this?
Also, any advice on how to further generalize the code in the event
handler would be appreciated. At first, I had all the checking in the
event handler, then I realized I should probably write my own method to
check. Basically what I want is if you click the word "Barbarian" while
one of three particular other radio buttons is clicked, I want the
message to appear. At first I had the alignment clear itself, but then I
figured it made more sense to clear the "Barbarian" radio button, since
that's what is being clicked in the first place.
public partial class frmCharacterManager : Form
{
private string incompatibleSelection = "Incompatible Selection";
public frmCharacterManager()
{
InitializeComponent();
}
private void rdoBarbarian_CheckedChanged(object sender,
EventArgs e)
{
string barbarianMessage = "The Barbarian class is
restricted to nonlawful alignments.";
if (CheckLawfulAlignment())
{
rdoBarbarian.Checked = false;
MessageBox.Show(barbarianMessage, incompatibleSelection);
}
}
public bool CheckLawfulAlignment()
{
if (rdoLawfulGood.Checked == true ||
rdoLawfulNeutral.Checked == true || rdoLawfulEvil.Checked == true)
return true;
else
return false;
}
}