Button and Enter key

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
 
?

=?ISO-8859-2?Q?=A3ukasz?=

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top