Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2007, 01:50 PM
Authorized User
 
Join Date: Feb 2007
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
 
Old June 18th, 2007, 05:13 PM
Wrox Author
 
Join Date: Oct 2005
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
================================================== =========
 
Old June 18th, 2007, 06:13 PM
Authorized User
 
Join Date: Feb 2007
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
 
Old June 18th, 2007, 07:02 PM
Wrox Author
 
Join Date: Oct 2005
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
================================================== =========
 
Old June 18th, 2007, 07:55 PM
Authorized User
 
Join Date: Feb 2007
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
 
Old June 18th, 2007, 09:20 PM
Wrox Author
 
Join Date: Oct 2005
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
================================================== =========





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





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