Click here to Skip to main content
13,899,733 members
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 20 Oct 2007
Licenced CPOL

Enter Key Behavior Extender

, 10 Apr 2010
Rate this:
Please Sign up or sign in to vote.
This component is used for forms that have too many textboxes which change their focus with Enter key.
Screenshot - top.gif


This article makes it easy to work with accounting applications and applications that need to fill their textboxes with numbers to change the focus to the enter key. This act increases the speed of users because enter key is behind the number keys and use of tab key is more difficult.

This work will be done with the following simple sentences.

It's enough to write the code in keyPressed event:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e) 
    if (e.KeyChar == (char)Keys.Enter ) 
        e.Handled = true; 
        Control control = GetNextControl((Control)sender, true); 

        if (control!= null && control.CanFocus) 

This component helps you to not write repeated and boring codes.

Using the Code

Add FocusProvider to the toolbox, then drag and drop. Now if you click on each TextBoxBase or ComboBox, you will be able to set their EnterPressed properties with suitable values.

Screenshot - FocusProvider.gif

It seems that it is unfavorable, but if there are many textboxes, it will be more suitable.

Thanks to

Homa for translating this article.

Screenshot - poem.gif


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ehsan Golkar
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
Artem S. Dmitriev10-Apr-10 6:47
memberArtem S. Dmitriev10-Apr-10 6:47 
GeneralMy vote of 1 Pin
Andy Missico27-Feb-09 5:19
memberAndy Missico27-Feb-09 5:19 
QuestionHow to... ? Pin
Vertyg022-Oct-07 22:37
memberVertyg022-Oct-07 22:37 
AnswerRe: How to... ? Pin
Ehsan Golkar23-Oct-07 19:16
memberEhsan Golkar23-Oct-07 19:16 
GeneralRe: How to... ? Pin
Vertyg023-Oct-07 20:11
memberVertyg023-Oct-07 20:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190306.1 | Last Updated 10 Apr 2010
Article Copyright 2007 by Ehsan Golkar
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid