473,320 Members | 1,945 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,320 software developers and data experts.

Can {Enter} tab to the next control?

Is there an easy way to make the {Enter} key take the cursor to the next
control without using a KeyDown event on each control?
Nov 16 '05 #1
3 5107
I haven't tried this, however, you might try wiring up a message filter
(IMessageFilter) and add it to the mix using the
Application.AddMessageFilter() method. You could check for an Enter key
press, eat that message, and then throw a Tab key press in it's place. This
may have consequences such as not being able to break to a new line in a
multiline TextBox, and maybe some other issues as well. But this should
place your Enter key handling at the application level.

--
Tim Wilson
..Net Compact Framework MVP

"Keith Smith" <ke*********@verizon.net> wrote in message
news:u1jXd.29279$uc.19146@trnddc09...
Is there an easy way to make the {Enter} key take the cursor to the next
control without using a KeyDown event on each control?

Nov 16 '05 #2
Oh, some other side effects could be the user not being able to select the
default accept button on a form or not being able to simulate a button press
when it has focus. So a solution at the application level may be too high up
to be done realistically. Unless, of course, you handle all the necessary
cases by checking where the message is directed and allowing certain Enters
to get through. If its not obvious, I'm really just thinking out loud on
this one.

--
Tim Wilson
..Net Compact Framework MVP

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:uL****************@TK2MSFTNGP12.phx.gbl...
I haven't tried this, however, you might try wiring up a message filter
(IMessageFilter) and add it to the mix using the
Application.AddMessageFilter() method. You could check for an Enter key
press, eat that message, and then throw a Tab key press in it's place. This may have consequences such as not being able to break to a new line in a
multiline TextBox, and maybe some other issues as well. But this should
place your Enter key handling at the application level.

--
Tim Wilson
.Net Compact Framework MVP

"Keith Smith" <ke*********@verizon.net> wrote in message
news:u1jXd.29279$uc.19146@trnddc09...
Is there an easy way to make the {Enter} key take the cursor to the next
control without using a KeyDown event on each control?


Nov 16 '05 #3
You could do it on a key event for the form, if you set the form.KeyPreview
to true. Or you could override the ProcessCmdKey() for the form. However,
it's not hard to have each control handle the KeyDown. You could call a
method in the Load() event of your form to attach them all. Something like:

void AttachKeyDownToControls(ControlCollection ccoll)
{
foreach ( Control c in ccoll.Controls )
{
if ( c.Controls != null )
{
AttachKeyDownToControls( c.Controls )
}
else
{
c.KeyDown += <whatever it is you do when you attach a KeyDown
event>;
}
}
}

This sort of thing works well if you only want to attach them to a certain
type of control. In the "else", you might really say

else if ( c is TextBoxBase && !c.Multiline )
// not sure if TextBoxBase really has multiline property but you get the
idea)
c.KeyDown += ...

"Keith Smith" <ke*********@verizon.net> wrote in message
news:u1jXd.29279$uc.19146@trnddc09...
Is there an easy way to make the {Enter} key take the cursor to the next
control without using a KeyDown event on each control?

Nov 16 '05 #4

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

Similar topics

3
by: Ali Eghtebas | last post by:
Hi, I have 3 questions regarding the code below: 1) Why can't I trap the KEYDOWN while I can trap KEYUP? 2) Is it correct that I use Return True within the IF-Statement? (I've already read...
6
by: Terry | last post by:
I have a form which is displayed in Datasheet View and would prefer it if, when entering data, I could use the keyboard as I would when entering data into a Datasheet. Is it possible when...
4
by: Ali Baba | last post by:
Hi, I need the enter key to work as a tab so that the focus goes to the next control. I don't want to write a KEY_PRESS handler for all controls. Is there a better way? IMPORTANT: I only want...
0
by: Mike Kingscott | last post by:
Totally hacked off here. I've written a user control that contains a text box, a required field validator and a button (these being the cornerstone of a search facility), all as ASP.Net server...
5
by: ewillyb | last post by:
Hi, ASP.NET has some interesting behavior when the user hits the Enter key. If there are multiple ASP:Buttons (rendered as HTML submits) on the form, when the user hits enter, the first button's...
12
by: SJ | last post by:
Hope someone can help me out there I'm struggling with a particular problem... I have a form with many tab pages. On one tab page I've got a button which when clicked with a mouse adds items...
1
by: Andrew | last post by:
Hi! I'm new to c# and I stumbled across this dillema during a project: can anyone tell me how I can emulate the action af a Tab when enter is pressed? I saw something in visual basic that looked...
4
by: portCo | last post by:
Hello there, I am using Visual Basic 2005. I want to store a value when I press enter key on the keyboard. Could anyone help me out? Thanks alot.
24
by: MichaelK | last post by:
Who knows how to prevent submitting a form on the press Enter button before all fields on the form are filled up. People just enter the first field hit Enter and it submits the form and doing...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
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...
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)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.