473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Windows Form RETURN/ENTER Key

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?

Nov 15 '05 #1
4 19036
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.
Nov 15 '05 #2
> 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!
Nov 15 '05 #3
> 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>
</html>
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
Nov 15 '05 #4
> 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.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
11
by: greg.scharlemann | last post by:
I've been playing with this form validation method for a while and have tried an array of things but haven't had any luck with a couple items. 1. The validateForm() function doesn't detect when...
6
by: Nurchi BECHED | last post by:
Hello, All! I have created an application with a multiline textbox on the form. When I press a button, it has to show something and then break the line and show something else. I tried "\n",...
0
by: Phil G. | last post by:
Hi, my 'project' requires that I create a form with text info. at set time periods. These time periods are not evenly spaced so I pass a param for the delay(seconds). In order to debug this I have...
1
by: kgerritsen | last post by:
I am building an application that will receive input from a barcode scanner. The barcode scanner is configured to append to the front value a single character and hyphen that identify the barcode...
2
by: Jibran | last post by:
I need some help with extra spaces in HTML form. There is a big white space appearing at the center of the HTML form that I am designing even though there is no <br> tags been used: ...
3
by: PrabodhanP | last post by:
I hv following javascript form validation code works in IE but not in Mozilla-Firefox ...please suggest <script type="text/javascript"> function IsNumeric(strString) // check for valid...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.