| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Managed C++ and C++/CLI Discuss Managed C++ and .NET-specific questions related to C++. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Capture a key stroke
How can I capture a Keystroke when in a TextBox and check if its the return key. I've IsInputChar() method but it dosen't seam to work.
|
|
#2
|
|||
|
|||
|
Re: Capture a key stroke
if (textBoxName->Text->Chars[i]==13) // 13 or KEY_ENTER look that up in the .net stdlib.h
Whatever the code for enter is, it might be ten, what I would do is check the values of what's in the textbox after you've pressed enter, either that or display each keypress's value that's entered into the textbox by changing the keypress event handler, just double click on the textbox and the IDE will create the function for you, and then write out MessageBox::Show(KeyPressValue::ToString() or use String::Format("{0}", KeyPress_Value) which should be simple enough to do. Otherwise, you would have to use more redirection or whatever with the TextBoxName->Text->ToCharArray()::Chars() something to that effect I don't want to open beta 2 right now and look. That should work, you could just check the value of the keypress before it's entered with making a TextBoxName_KeyPress procedure, I don't know exactly how to do that without looking. |
|
#3
|
|||
|
|||
|
Re: Capture a key stroke
The functions you mentioned work if a keystroke causes entry into the procedure for that box. But the enter key does not cause entry into the event handler for that box. In MFC there is a PreTranslateMessage handler that you can use I'm looking for something along that line. Thanks for the reply that was some good info.
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|