473,546 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 19039
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(ob ject 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="JavaS cript">
function setInitialFocus (initial_contro l) {
initial_control .focus();
}
</script>
</head>

<body onload="setInit ialFocus(test.u ser_name);">
<form name="test" action="somethi ng" 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(ob ject 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
4870
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 because then it didn't work in IE. How can I enable this javascipt form validation to work in Netscape? When I use netscape, none of the alert boxes...
7
3581
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> </head> <style type="text/css">
2
2282
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 can use that will work for both browsers, or is there something wrong with my code? I seem to think that the problem lies with the "onclick" area of...
11
2509
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 the Min price is greater than the maximum price. 2. The validateForm() function doesn't call isNumber() on the minBaths, maxBaths, minBeds, or...
6
16236
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", ((char)13) and ((char)10) - they don't work. When I enter a break by hand (just press enter) and run through each character in that string, the line...
0
1242
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 created a form with a button, textbox and NumericUpDown. Textbox holds the message to be displayed on the newly created form and the NumericUpDown...
1
4747
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 standard, then the value in the barcode, terminated by a return. The barcode scanner appears to the operating system as a USB keyboard. I am...
2
4694
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: http://i116.photobucket.com/albums/o9/Jibran82/Pic1.jpg The html code is below: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
3
5549
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 numeric strings { var strValidChars = "0123456789.-"; var strChar; var blnResult = true;
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.