Message Box in An event handler code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

iam getting too many messages boxes when i include a message box in a KeyUP eventhanler function which in turn have validation if functio
my code i
when i press the ok button of the message box , message box pops again how to avoid it

private void txtJobName_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e

if(e.KeyValue == 1

MessageBox.Show("xyz")
txtJobName.Focus()


}
 
Anil said:
iam getting too many messages boxes when i include a message box in a KeyUP eventhanler function which in turn have validation if function
my code is
when i press the ok button of the message box , message box pops again how to avoid it?

private void txtJobName_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyValue == 13
{
MessageBox.Show("xyz");
txtJobName.Focus();
}

}

The problem is, when you press ENTER again to clear the message box,
your text box eventually gets another "key up" message, and shows
another message box.

Put the code in a KeyPress event handler instead, and this problem
won't occur:

private void txtJobName_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == 13) {
MessageBox.Show("xyz");
txtJobName.Focus();
}
}
 
Back
Top