perlnewbie9292
Programmer
Hello,
New to C#, I have been trying to figure out why the keyUP event I coded continues to trigger and how to suppress it.
KeyUp code that I am using is shown below. I have tried handled, suppressKeyPress, but neither keep it from firing once it performs the performClick action.
What I am trying to do is:
if the user hits Enter when they are in the textbox, it should have the same effect as if they clicked the addrFormGenerateButton (which is why i am sending it to addrFormGenerateButton.PerformClick()).
Not sure if this is the correct way to do this, if it is, then how do I keep all subsequent enters from firing.
Currently, if I hit the Enter button and generate and error due to invalid data in the textbox, when I click Enter to accept the messageBox this event fires again and again.
Thanks for all the help in advanced.
New to C#, I have been trying to figure out why the keyUP event I coded continues to trigger and how to suppress it.
KeyUp code that I am using is shown below. I have tried handled, suppressKeyPress, but neither keep it from firing once it performs the performClick action.
What I am trying to do is:
if the user hits Enter when they are in the textbox, it should have the same effect as if they clicked the addrFormGenerateButton (which is why i am sending it to addrFormGenerateButton.PerformClick()).
Not sure if this is the correct way to do this, if it is, then how do I keep all subsequent enters from firing.
Currently, if I hit the Enter button and generate and error due to invalid data in the textbox, when I click Enter to accept the messageBox this event fires again and again.
Thanks for all the help in advanced.
Code:
private void addrFormTextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
e.SuppressKeyPress = true;
addrFormGenerateButton.PerformClick();
}
}
private void addrFormGenerateButton_Click(object sender, EventArgs e)
{
string validPathRequiredErrorString = "Please enter a valid address before attempting to process.";
string validPathRequiredErrorBoxString = "Valid path required!";
this.addrFormTextBox.KeyUp += new System.Windows.Forms.KeyEventHandler(this.addrFormTextBox_KeyUp);
if (this.addrFormTextBox.Text.Length == 0 || this.addrFormTextBox.Text == null)
{
MessageBox.Show(validPathRequiredErrorString, validPathRequiredErrorBoxString);
return;
}