Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

Vote on your favorite hash algorithm here!

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-2006, 07:53 PM
Chan Chan is offline
Programming Professional
 
Join Date: Jun 2006
Posts: 204
Credits: 1
Rep Power: 10
Chan is on a distinguished road
Default Getting keypress Enter

How do I capture when the user presses the enter key in a certain text box?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-07-2006, 07:08 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 7,397
Last Blog:
Tramp Variables
Credits: 1
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Capture the "keypress" event of your control and add this code:

Code:
if (e.KeyChar == (char)13)
{
    // Code
    ......................
}
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Don't hesitate to ask any questions that you have! Check out our ASCII Calculator!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-07-2006, 08:46 PM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Credits: 0
Rep Power: 10
brackett is on a distinguished road
Default

Jordan's got it right. Though I'd recommend using the System.Windows.Forms.Keys enum instead of 13. Just a style guidance, though - functionally, it should be the same.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-08-2006, 08:27 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 7,397
Last Blog:
Tramp Variables
Credits: 1
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Actually, that is the way I prefer it too brackett but I couldn't get it to work in C#. I looked through all of the properties of e in the above code and nothing would would convert. So, for instance

Code:
if (e.keychar == system.windows.forms.keys.enter) {}
will not compile.

in managed C++ 2.0 I know there is a keycode property of KeyEventArgs so code would look like this:

Code:
if (e->KeyCode == System::Windows::Forms::Keys::Enter)
Not sure if this is a bug or what.....
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Don't hesitate to ask any questions that you have! Check out our ASCII Calculator!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-08-2006, 03:16 PM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Credits: 0
Rep Power: 10
brackett is on a distinguished road
Default

Quick browse of MSDN2 shows that KeyDown and KeyUp use KeyEventArgs, which includes the KeyCode property. KeyPress uses KeyPressEventArgs, which does not have a KeyCode property (only KeyChar).

Unfortunately, it also states that without overriding the IsInputKey method of the control, Enter will be handled by the control directly and not raise the KeyDown/KeyUp events. I'm unclear on whether KeyPress is raised or not.

Yeah - I think there's a design mistake in there somewhere. You'd think KeyPressEventArgs would inherit from KeyEventArgs (adding the Handled flag). But, as it stands, I guess casting to char is the easiest way to do it.

I'd suspect System.Windows.Forms.Keys.Enter is 13, so you could cast that to char. At least it'd give some contextual information on what you're trapping.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows XP Tricks & Tips!!!!..new ones. pranky Tutorials 9 08-23-2008 03:22 PM
Enter Password first TcM PHP Forum 4 06-14-2007 10:02 AM
Help in SLR parser vithasekar C and C++ 3 02-15-2007 01:50 AM


All times are GMT -5. The time now is 10:58 PM.

Contest Stats

Xav ........ 1357.94
MeTh0Dz|Reb0rn ........ 1077.71
WingedPanther ........ 919.18
marwex89 ........ 906.86
morefood2001 ........ 900.18
John ........ 890.77
Brandon W ........ 770.65
chili5 ........ 312.39
Steve.L ........ 264.99
dcs ........ 234.34

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 83%

Ads