MTSkull Posted August 21, 2006 Posted August 21, 2006 How do I create a keypress event for C#? I want something like. private void MyTextBox_Keypress (object sender, EventArgs e) { if (keypressed == "Enter Key") nextControl.Setfocus; } Quote "Beer is proof that God loves us and wants us to be happy." -Benjamin Franklin
Leaders snarfblam Posted August 21, 2006 Leaders Posted August 21, 2006 Attach the handler through the IDE (select the text box, go to the properties window, and click the lighting bolt icon, find your event, and select an event handler or double click the event to create a new handler). The code for the handler should probably look something like this (handling certain keys for certain controls in certain versions of .Net can be a pain, though): // I would prefer KeyDown over KeyPress because it works with keys instead of the characters that they represent private void MyTextBox_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Enter) nextControl.Focus(); } Quote [sIGPIC]e[/sIGPIC]
MTSkull Posted August 22, 2006 Author Posted August 22, 2006 Thanks Works perfectly thanks. Quote "Beer is proof that God loves us and wants us to be happy." -Benjamin Franklin
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.