Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox - keypress/keydown with Enter key

Status
Not open for further replies.

sodakotahusker

Programmer
Mar 15, 2001
601
0
0
I am trying to do something very simple. I have a textbox that I want to all the user to press Enter when they are finished typing to initiate a search. Neither keydown or keypress event fires when I use the enter key. The events fire for other keys so I know the handler is set up correctly. The property on the textbox for AllReturn is set to Yes.
The only difference with these textboxes from ones I have used these events on in the past are that they are drawn on the mdi parent. Can the form be swallowing those keystrokes???
Thanks!!!

 
You could show us your code for that (how to handle the eneter press)

Anyway:

Code:
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                MessageBox.Show("Enter pressed !");
        }
 
Check if your parent form has KeyPreview turned on and if you're cancelling the Enter keystroke already.

Also: when you get this working on the textbox, this is the time to cancel the keypress (since nothing else needs to grab it) so make e.Cancel = true;

This will stop the application from beeping on every search.
 

I had checked that just before I posted here. It is set to false. Another circumstance that might be a factor. This textbox is drawn on a component one outlook menu control. I could not find a property on that control that would have such an impact. I just tried stepping to make sure no events were firing before keydown. Nada. It just won't fire on the enter key.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top