>>
Home

>>
All About Me

>>
Books

>>
Events

>>
Links

>>
Photo Gallery

>>
Downloads

>>
Visual Basic .Net

>>
SE IERP

>>
FPU

>>
My Tubes



Login
Register

All content is the property of TimKey.Net unless noted otherwise in the content. All rights reserved




Trap The Enter Key In VB.Net

Posted by on Friday, January 07, 2005 (CST)

Ever want to trap the Enter key in the Keypress Event? Here's how.

All you need to do is copy and past the segment of code below into the keypress event of the control.

 

        If Asc(e.KeyChar) = Keys.Enter Then
            'Do something here

            e.Handled = True
        End If

 

 

That's it, I hope you find it useful...

 

 


Comments:

trap enter key on keypress event of datagrid in vb.net.
By pawan on Tuesday, April 26, 2005 (CST)

I see your code use this code but not work on enter key.

if i press shift+enter then this work.but

 i want to use only enter key.

so plz give some code + gide for this work.

thank you.

pawan

Reply to this Comment

Re: Trap Enter Key
By tkey on Wednesday, June 22, 2005 (CST)

I am not sure I understand what you are asking here.  This is the way it works for me when I test this code.

I put this code in the KeyPress event of a text box and no matter if I hit enter or shift enter I am still able to capture the Enter Key.

The only difference to this is if you have set a default Accept Button on your form which will override the code you put in the KeyPress. 

Am I missing what you were asking or does this answer your question?

 Tim

Reply to this Comment

Asc()
By Collinsauve on Wednesday, July 02, 2008 (CST)
Your method uses the Asc() Function, which is contained in Microsoft.VisualBasic and is therefore unmanaged code... Do you know the managed equivilant I am looking for it...

Reply to this Comment

Re: Asc()
By tkey on Wednesday, July 02, 2008 (CST)
Try this one on the KeyDown event Private Sub Button1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyDown If e.KeyCode = Keys.Enter Then 'Do something e.Handled = True End If End Sub

Reply to this Comment

Add Your Comment



Trinity Faith Fellowship

May the smile on your face Come straight from your heart
--- Anonymous

 

New Books

  • Enchanters' End Game
    Publishers Weekly
    "Absorbing. Touches all the right Fantasy bases. Warring gods, political intrigues, supernatural creatures, and appealingly human magicians."


  • The Misanthrope and Tartuffe
    Two classic plays translated by a Pulitzer Prize-winning poet into English verse. Introductions by Richard Wilbur.



  • Castle of Wizardry
    This is like Bonanza, or like I Love Lucy. There will be other fantasy series, but there can never be another that's so seminal, that so captures the essence of fantasy. Big Dave and Little Leigh grow their heroes from the ground up, and they grow the best.

  •  

    New Links

  • Kids and Guns
    My Daughter getting shooting lessons from my Dad. She should listen better...

  • QuickVerse Starter 2005
    Free KJV Bible for your PC. This is the best PC Bible software I have found anywhere and believe me I have looked and tested for years.

  • Free Bug Tracking Software
    Get your free version of PR-Tracker

  •  

    New Posts

  • on site visit
    Posted by linda on Friday, November 14, 2008 (CST)

  • ERP 5.2 Return Material Authorisation troubleshooting
    Posted by Noreen on Tuesday, August 12, 2008 (CST)

  • ERP 7.2 Buyers Workbench
    Posted by rcanavan on Wednesday, November 28, 2007 (CST)

  •  

    Most Popular Books
  • Loose That Man And Let Him Go
    FROM THE PUBLISHER
    Never in the history of the church has there been a time when God has so urgently stirred the hearts of men to become all He created them to be and accomplish all He created them to accomplish.


  • Why Do Men Have Nipples? Hundreds of Questions You'd Only Ask a Doctor After Your Third Martini
    Is There a Doctor in the House? You will laugh outloud as you read this book. This is one of my favorite books of all time. Told in a very humorous manner but with all seriousness, you will be enlightened about hundreds of areas of life we have al

  • Silent No More
    “Silent No More,” expounds upon the issues of our day, including judicial tyranny, race relations, poverty, homosexuality, Islam, education, and the right to life. Pastor Parsley provides practical action steps to engage readers and motivate them to act.


  • Home   |  All About Me   |  Books   |  Events   |  Links   |  Photo Gallery   |  Downloads   |  Visual Basic .Net   |  SE IERP   |  FPU   |  My Tubes