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

Trying to make text box 1 active after text box 2 has enter key pressed

If I have text box 1 (Password Enter) and I have text box 2 (Password Reneter).

After text has been entered in text box 1 and the enter key is pressed to make text box 2 active (the curser will jump from text box 1 to text box 2.

Any ideas
Mar 28 '09 #1
3 5568
tlhintoq
3,525 Expert 2GB
After text has been entered in text box 1 and the enter key is pressed to make text box 2 active (the curser will jump from text box 1 to text box 2.
Are you trying to ask "How do I make the cursor move from textbox1 to textbox2 when the user presses the enter key in textbox1?"

In textbox1 handle the KeyPress event something like this
Expand|Select|Wrap|Line Numbers
  1.         private void tbPassword_KeyPress(object sender, KeyPressEventArgs e)
  2.         {
  3.             if ((Keys)e.KeyChar == Keys.Enter) btnLogInRead_Click(this, EventArgs.Empty);
  4.             if ((Keys)e.KeyChar == Keys.Up) tbName.Focus();
  5.             if ((Keys)e.KeyChar == Keys.Right) btnLogIn.Focus();
  6.         }
  7.  
In this example you can see 3 different actions that could take place:
If [Enter] is pressed it is the same as clicking the "LogInRead" button. This is where you might want to have it shift fields. Me personally, I always expect an enter key to press the default button on the form.
If the [Up] arrow key is pressed, then focus shifts to the "Name" textbox.
if the [right] arrow key is press, focus shifts to the LogIn button (but doesn't click it)
Mar 28 '09 #2
IanWright
179 100+
Far easier than that is to setup the tab index correctly for all your controls. It should then jump automatically I believe, certainly will if the user presses tab which is consistent with most password UI's.
Mar 30 '09 #3
tlhintoq
3,525 Expert 2GB
Its always easier to change the conditions that you want to match the behavior of the program, than to change the behavior of the program to match the user desires. But that's not the way we are supposed to write code. Coders do not tell the client how their work flow is supposed to go, or how they have to work the program to make it behave. We have a responsibility to provide a good user experience in addition to the requested functionality. "Good enough" is never good enough.

In this case BOTH should/could happen. The tab order should be set so standard WIndows conventions of tabing are followed. But the OP's stated desire was to have the same behavior when the [enter] key was pressed.

We love options.

Though I agree with you. Generally speaking I don't use [enter] as a tab. But it can be handy to monitor it just the same. For example you could have a Username and a Password text box with no [submit] button at all. Tab between the two fields and pressing [enter] checks the user's credentials. As you can see in the sample code I provided pressing [enter] is the same as clicking the LogIn button, not the same as tabbing to the next control.

This can let you provide more intuitive behavior than just [tab]. Notice that the up and down keys are mapped to other controls. I think its always nice for a user to not have to hit [tab] 47 times to get to a control directly above the current control. It doesn't take much to have all your text boxes in an array and to calculate that the control directly [up] is the one 16 before the current one, for example. [up] 3 times beats repeatedly mashing [SHIFT] + [TAB]
Mar 30 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Piotr | last post by:
I need a VBA macro to copy all text from text objects in the igrafx flowcharter Diagram to clipboard or to save it to a text file (in order to count the text I translated). I tried the...
2
by: Hareth | last post by:
i got the idea "form.textbox.text = label.text" from vb... i tried it in C# but it generated errors i found a diff example from :...
5
by: grs | last post by:
If you do a maskTextBox.String() the mask characters are still in the string. Surely MS does not want you to store the masking characters - where is the method to remove the masking characters. ...
14
by: deercreek | last post by:
Could use some help. I don't know if I can even do whatI'm trying to do. I have a text box in a report under the details section. It will return a value for each line on a sepcific record set....
7
by: bobd314 | last post by:
Currently, I am having a problem replacing the value of a input box with something else using the innerHTML thing. Right now I have something going <script type="text/javascript"><!-- function...
1
by: Rodrigo Costa | last post by:
Hi people... can anyone help on how to make a full-text search accent insensitive on a mdb database ? thx
4
by: Dan | last post by:
Hi all, I am creating a search table where the keywords field is made up of several text fields and this is causing me some problems. I can concatentate the text ok but i can't seem to concatenate...
4
by: shihab | last post by:
I have one multi line text box.i want to 'add text this text box one by one' from database(eg.Customer Name Field).i am using C#.plz give me a solution thanx shihab
5
sukumar 123
by: sukumar 123 | last post by:
How to make an email text box as a readonly using dojo widget?
6
by: chanshaw | last post by:
Hi I'm trying to get the text from the selected <option> of a <select> function loadSelectQuestion() { var dropdownIndex = document.getElementById('selectCategory').value;...
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...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.