如何清除&输入并检测到错误值后显示我清除的表单值
我想弄清楚如何清除&输入并检测到错误值后显示(重置)我清除的表单值。目前,当我发现错误的输入时,即使我再次单击输入按钮,它也只是坐在那里。任何帮助将不胜感激。
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();
}
}
}
I am trying to figure out how to clear & display (reset) my cleared form values after an incorrect value has been entered and detected. Currently when I catch an incorrect input, it just sits there, even after i have clicked the enter button again. Any help would be greatly appreciated.
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();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯。 。 。所以我想通了。这只是我犯的一个逻辑错误:)
}
Uhm. . . so I figured it out. It was just a logic error that I had done :)
}