Old dude
Old dude

Reputation: 11

C# - I want to hit Enter, not click on the "button" to activate program

I'm just learning C#. I created a Windows Form Application. It works, but you have to click on the "Calculate" button that I created to activate the program. I would like to be able to just hit Enter on my keyboard. I thought maybe there was a properties setting for the button but I don't see one.

Any ideas?

Upvotes: 0

Views: 99

Answers (2)

Goody Tenzor
Goody Tenzor

Reputation: 21

You could listen for the KeyUp event

using System.Windows.Forms;

private void btnSubmit_KeyUp(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Enter)
        MessageBox.Show("You hit the Enter key.");
}

Upvotes: 2

Selman Genç
Selman Genç

Reputation: 101681

You are looking for Form.AcceptButton property

Gets or sets the button on the form that is clicked when the user presses the ENTER key.

Upvotes: 8

Related Questions