Button and Enter key

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

Guest

Hello,

A button can be clicked by using the mouse, ENTER key, or SPACEBAR if the
button has focus. Is there a way for me to make it so that hitting ENTER when
a button has focus does nothing? I don't want ENTER to ever cuase the
button's click event to be risen.

Thanks,
-Flack
 
Flack said:
Hello,

A button can be clicked by using the mouse, ENTER key, or SPACEBAR if the
button has focus. Is there a way for me to make it so that hitting ENTER when
a button has focus does nothing? I don't want ENTER to ever cuase the
button's click event to be risen.

Thanks,
-Flack
There is KeyPress event.

You can write:

private void button_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar == ControlChars.Lf)
{
e.Handled = true;
}
}

But I didn't test it.

£ukasz
 
Back
Top