|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||||
|
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! |
|
|||
|
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.
|
|
|||||
|
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) {}
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)
__________________
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! |
|
|||
|
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. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |
Goal: 100,000 Posts
Complete: 83%