Windows Form RETURN/ENTER Key

  • Thread starter Thread starter Juan Gabriel Del Cid
  • Start date Start date
J

Juan Gabriel Del Cid

No, to change the default behavior of Enter, Tab, etc. you must write the
code yourself. You want to handle the KeyPress event and check for
Keys.Enter, like so:

private void xxx_KeyPress(object sender, KeyEventArgs e) {
if (e.KeyData == Keys.Enter) {
// etc
}
}

Hope this helps,
-JG

PS. I once had a big argument with a client about this issue. In my opinion,
it is not a good idea for an application to change standard Windows UI
behavior.
 
I guess us pre-mouse old timers like that traditional enter, exit thing.
The
RETURN key is easy to reach and a great way to form exit. I think that's an
old IBM standard. I agree with you about messing with defaults these days.
It does take a part of a second longer to grab the mouse and click it, so I
guess it would have to be a really data entry intensive application to want
to mess with it.

I hate using the mouse too, :-D. I use the keyboard shortcuts as much as I
can. That is partly why I don't like to "adjust" to another interface when
dealing with different applications. I like Tab to take me to the next
control and Enter to submit (granted there are no errors with my input).
Could someone let me know if falls within the list guidlines to ask another
type question like how on a web form to get an initially displayed web page
field to have focus. You always have to click in the field the first time.

Use JavaScript:

<html>
<head>
<script language="JavaScript">
function setInitialFocus(initial_control) {
initial_control.focus();
}
</script>
</head>

<body onload="setInitialFocus(test.user_name);">
<form name="test" action="something" method="post">
Please enter the name: <input type="text" name="user_name">
<input type="submit" value="Go">
</form>
</body>
I see this type of question has a good chance of not being responed to. With
people not wanting to post their email addresses I guess it's hard to take
these questions off the list.

If you look closely, you can deduce peoples email addresses. Just take away
phrases like 'stop-spaming-me' or 'nospam' and the like.

Hope that helps,
-JG
 
My windows form has some text boxes and a two buttons, Button1 and Button2.
The TAB key goes from field to field. When the user presses the RETURN key I
want the focus to be moved to Button1. Is there an easy way to do this or
would I have to check for all keypresses in an event somewhere and manually
set the focus on Button1 if the RETURN key was hit. Is so, which event would
that be?
 
PS. I once had a big argument with a client about this issue. In my
opinion,
it is not a good idea for an application to change standard Windows UI
behavior.

I guess us pre-mouse old timers like that traditional enter, exit thing. The
RETURN key is easy to reach and a great way to form exit. I think that's an
old IBM standard. I agree with you about messing with defaults these days.
It does take a part of a second longer to grab the mouse and click it, so I
guess it would have to be a really data entry intensive application to want
to mess with it.

Could someone let me know if falls within the list guidlines to ask another
type question like how on a web form to get an initially displayed web page
field to have focus. You always have to click in the field the first time. I
see this type of question has a good chance of not being responed to. With
people not wanting to post their email addresses I guess it's hard to take
these questions off the list.

Thanks for the reply!

Have a great weekend!
 
dealing with different applications. I like Tab to take me to the next
control and Enter to submit (granted there are no errors with my input).

When I hit the ENTER/RETURN key on my Windows Form it does'nt do anything. I
understand your keypress trap for the key:

private void xxx_KeyPress(object sender, KeyEventArgs e) {
if (e.KeyData == Keys.Enter) {
// etc
}
}

I know on a web form the RETURN key submits. Is that what you are referring
to? Is there also a Windows Form propery that can be set to make the RETURN
key have the same function as the ENTER key? Does using a FormBorderStlye of
FixedDialog have an affect on the key behavior? I guess I could test that,
but I like using FixedDialog Windows Forms.
 
Back
Top