How to get 'ENTER' key event for a button...?

Hi...

In my application i want to an event for ENTER key pressed on keyborad.

Actually i have entered some values in textbox & on pressing a button i should save that value in a variable. & i want same thing should happen if i press ENTER key on keyboard.

How can i do this...

Thanks inadavance,

Vinay



Answer this question

How to get 'ENTER' key event for a button...?

  • DrChuck

    You can handle KeyPress event of textbox control and check the pressed key. Also you can handle KeyDown event in the same way. But maybe the best solution is to create a new TextBox control inherited from TextBox and on that control to override the ProcessCmdKey method.

  • Tom_Tregenna

    again, everything you need is in the KeyDown event. you just check the e parameters and thats it. so CTRL + C:

    if (e.Control && e.KeyCode == Keys.C)

    {

    ///do your thing

    }



  • Michael Hansen

    Thanks...

    It helped me a lot...One more thing can i give similar keyboard events for other keys also...like... CTRL+C...

    Can i do like this...

    Thanks for your replies...

    Vinay


  • Siteadm

    on the textbox keydown event (click textbox. Go to its properties. Click on the lightning symbol, this is the events tab. Double click the keydown event), check to see what key was pressed from the KeyEventArgs parameter. If its enter, then save or do whatever:

    if (e.KeyCode == Keys.Enter)

    {

    //do your thing

    }

    does this help



  • How to get 'ENTER' key event for a button...?