0

Hi everyone,

I am making a windows application in which I want that when user presses enter key while textBox1 has focus then an event is generated. I tried using following but it doesn't workout:-

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.GetHashCode() == Keys.Enter.GetHashCode())
            MessageBox.Show("Enter key has been pressed");
    }

Please help.

Edited by mike_2000_17: Fixed formatting

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by ssbark
0

Hi
Do this:
Help with Code Tags
csharp Syntax (Toggle Plain Text)

1. if (e.KeyChar == (char)Keys.Enter)
2. {
3. //do something
4. }

inside textBox1_KeyPress function

Thanks for replying, I got the result.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.