2010-05-12 90 views
1

我怎樣才能讓它在某處按下輸入鍵在我的表單上它會提交此代碼?使回車鍵像提交按鈕

我試過KeyPress事件等......但我似乎無法弄清楚。

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"); 

    } 
+1

'ligtning bolt events' - Classic :) – Kelsey 2010-05-12 15:28:16

+0

您正在問一個asp.net或winforms? – Elph 2010-05-12 15:29:51

回答

4

如果這是WinForms,請將表單的AcceptButton屬性設置爲您想要點擊模擬的按鈕,當他們按時輸入。然後,在該按鈕的事件處理程序中,請致電Close()或更好,請設置DialogResult屬性

0

那麼,如果你使用的WinForms我認爲你這樣做有一個按鍵事件:

0

回車是一個重點新聞。您需要製作一個按鍵事件處理程序。