如何在某人按下表单上的回车键的情况下将其提交给提交此代码?
香港专业教育学院尝试过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");
}
Run Code Online (Sandbox Code Playgroud)
您可以将表单的AcceptButton属性设置为您的按钮:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx
"获取或设置用户按下ENTER键时单击的表单上的按钮."
| 归档时间: |
|
| 查看次数: |
4648 次 |
| 最近记录: |