2010-05-12 109 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

回车是一个重点新闻。您需要制作一个按键事件处理程序。