dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersA'zlina
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » Active Directory

C# - Press Enter Key to move to next control on a Windows Form


Posted Date:     Category: Active Directory    
Author: Member Level: Bronze    Points: 15


Many times while working on Windoes forms we get into situation where we want to move to controls using ENTER key. To make it simple below is the detailed code. its very simple 1. Select the Form where this needs to be applied. 2. Set the Forms Key Preview Event. 3. Write the Keydown even for the Form. 4. Set the Code to fire the Tab control.



 


C# - Press Enter Key to move to next control on a Windows Form using single code
-------------------------------------
1. In the Form, Select Form--> Press F4 to open the Property box. or
Click on View Menu--> Property Window menu item.
2. This will open the Property box.
3. Look for property KEY PREVIEW and set it to TRUE.
This will make the form listener to all events we are performing on Controls. This is useful to avoid writing Lost Focus() code for each control.

4. Now here is the little code you need to write for Forms KeyDown event.

//Code to be pasted in your form. My Form name is frmNewInput. Change your code as appropriate formname.

private void frmNewInput_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.SelectNextControl(this.ActiveControl, true, true, true, true);
}
}

Note: Please dont use that (Control)sender instead of this.ActiveControl as this wont work because it wont understand which control to focus now. As you must be aware that SelectNextControl(..) is a in-built into .NET framework 3.5 so there is no hassle or performance issues.

You can freely use my code in yours and make your creations well.

Attachments

C# - PRESS ENTER KEY TO MOVE ...





Did you like this resource? Share it with your friends and show your love!


Responses to "C# - Press Enter Key to move to next control on a Windows Form"
Guest Author: Abhirup     19 Jun 2012
Really Excellent one. This helped me a lot.

Thanks Nikesh



Guest Author: bharat     29 Oct 2012
thanks sir, i need it and i like it but i want to previous so what can i do ?
please response with bharat@macfuturetechsoft.in



Author: Nikesh Kumar Sinha    30 Nov 2012Member Level: Bronze   Points : 3
Hello Bharat,
thanks for the comment. For the Previous, you need to make a small change :

change the first bool Parameter to false. It will look below :

this.SelectNextControl(this.ActiveControl, false, true, true, true);

I tested it and it works well. Hope it will work for you too. Write to me in case you have any issue.

Regards,
Nikesh



Guest Author: Nikhil Jain     14 Dec 2012
Thanks Nikesh

its very useful

-Nikhil Jain



Guest Author: Gopal     28 Dec 2012
really nice1


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to read DataReader Columns by their names?
    Previous Resource: Find and delete a specific row from datatable
    Return to Resources
    Post New Resource
    Category: Active Directory


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    VB.NET windows form  .  TAB Key  .  Lost Focus  .  Microsoft .NET  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.