Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 18th, 2007, 01:50 PM
Authorized User
 
Join Date: Feb 2007
Location: , MN, USA.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default textbox

How can I create an event that detects when the user has pressed the enter key while in a textbox?? I have searched around, but the only example I found were very complicated and proprietary.

There are 10 types of people - Those who understand binary, and those who don't.
http://bschleusner.googlepages.com/home
__________________
There are 10 types of people - Those who understand binary, and those who don\'t.
http://bschleusner.googlepages.com/home
  #2 (permalink)  
Old June 18th, 2007, 05:13 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Handle the OnKeyDown event and then test if the textbox is the active control:

TextBox textBox = this.ActiveControl as TextBox;
if(textBox == null){return;}
else if(textBox == myTextbox){//do something}

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #3 (permalink)  
Old June 18th, 2007, 06:13 PM
Authorized User
 
Join Date: Feb 2007
Location: , MN, USA.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, that helps, but now how do I tell if the key that was pressed was the enter key?

There are 10 types of people - Those who understand binary, and those who don't.
http://bschleusner.googlepages.com/home
  #4 (permalink)  
Old June 18th, 2007, 07:02 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In the EventHandler for the KeyDown event you would do something like:

if(e.KeyCode = Keys.Enter){//do something}
else{//do something else}

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #5 (permalink)  
Old June 18th, 2007, 07:55 PM
Authorized User
 
Join Date: Feb 2007
Location: , MN, USA.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, that works great!

There are 10 types of people - Those who understand binary, and those who don't.
http://bschleusner.googlepages.com/home
  #6 (permalink)  
Old June 18th, 2007, 09:20 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

;] Glad it worked out for you.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TextBox Help iceman90289 C# 2005 6 April 6th, 2008 03:54 AM
pointing cursor from one textbox to other textbox lakshmi_annayappa ASP.NET 1.0 and 1.1 Basics 2 August 2nd, 2007 03:41 PM
Textbox deontae45 VB.NET 2002/2003 Basics 1 September 25th, 2006 11:26 AM
Masked TextBox & formatting TextBox melvik C# 1 September 22nd, 2003 11:01 AM



All times are GMT -4. The time now is 07:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.