Я пытаюсь выяснить, как очистить и отобразить (сбросить) мои очищенные значения формы после того, как было введено и обнаружено неправильное значение. В настоящее время, когда я ловлю неправильный ввод, он просто остается там, даже после того, как я снова нажал кнопку ввода. Любая помощь будет принята с благодарностью.
namespace Mileage
{
public partial class Form2 : Form
{
private double beginMileage, endMileage, gallons, mpg;
public Form2()
{
InitializeComponent();
}
//Enter button click
public void menuItem1_Click(object sender, EventArgs e)
{
if (endMileage<beginMileage)
{
this.label5.Text = String.Format("ERROR: End mileage is less than begining mileage.");
}
else if((endMileage<0)||(beginMileage<0))
{
this.label5.Text = String.Format("ERROR: One or more mileage input is negative.");
}
else if ((endMileage == 0) || (gallons == 0))
{
this.label5.Text = String.Format("ERROR: The end mileage and/or gallon input is zero.");
}
else
{
beginMileage = double.Parse(this.textBox1.Text.Replace(" ", ""));
endMileage = double.Parse(this.textBox2.Text.Replace(" ", ""));
gallons = double.Parse(this.textBox3.Text.Replace(" ", "")) ;
mpg = ((endMileage - beginMileage) / gallons);
this.label5.Text = String.Format("{0}", mpg);
}
}
//exit button click
public void menuItem2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}