Make the Enter key act like the submit button

Posted by Michael Quiles on Stack Overflow See other posts from Stack Overflow or by Michael Quiles
Published on 2010-05-12T15:24:19Z Indexed on 2010/05/12 15:34 UTC
Read the original article Hit count: 189

Filed under:

How can I make it where some one presses the enter key on my form it will submit this code ?

Ive tried the ligtning bolt events etc... but I can't seem to figure it out.

 private void
 xTripSubmitButton_Click(object sender, EventArgs e) { 
    //  Calculates the numbers from the input and output boxes/labels
    Miles = double.Parse(this.xTripDestinationTextBox.Text);
    Mpg = double.Parse(this.xTripMpgTextBox.Text);
    Price = double.Parse(this.xTripPricepgTextBox.Text);
    Output = Miles / Mpg;
    Coutput = Output * Price;

    //displays a message and the result for the numbers the user inputs
    this.xTripOutputLabel.Text = "Total gallons you would use: " +
        Output.ToString("0") +
        Environment.NewLine + "Total amount it will cost you: " +
         Coutput.ToString("C"); 

    }

© Stack Overflow or respective owner

Related posts about c#