Reputation: 31
I Have a login form. In the KeyUp
event of txtUserName
textbox have this,
private void txtUserID_KeyUp(object sender, KeyEventArgs e)
{
if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
{
//Next control when Press Enter key
SelectNextControl((Control)sender, true, true, true, true);
}
}
But everytime i press Enter Key
,Focus goes to next contol and produce a System warning sound.
How can i avoid this or What is the wrong with this?
Upvotes: 0
Views: 267
Reputation: 34152
When you press enter key, along side your code, the default event fires too.
Add e.Handled = true
, to your method:
private void txtUserID_KeyUp(object sender, KeyEventArgs e)
{
if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
{
//Next control when Press Enter key
SelectNextControl((Control)sender, true, true, true, true);
e.Handled = true
}
}
This tells that event is handled.
Upvotes: 1