Avik
Avik

Reputation: 2137

Submit by pressing enter in a windows form

In order to transfer text from one textbox to another, I have created a submit button. However it would be preferable to use the functionality of the 'enter' key.

I am not sure but i think the ascii code is 13.Anyway how do I go about this task at hand?

Upvotes: 8

Views: 16712

Answers (2)

Brownman98
Brownman98

Reputation: 1065

You can subscribe to the KeyUp event of the text box.

using System.Windows.Forms;

private void txtInput_KeyUp(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
        DoSomething();
}

Upvotes: 5

leppie
leppie

Reputation: 117220

Look at the Form.AcceptButton property.

Upvotes: 23

Related Questions