【问题标题】:how to clear & display my cleared form values after an incorrect value has been entered and detected输入和检测到不正确的值后如何清除和显示我清除的表单值
【发布时间】:2010-12-05 18:57:25
【问题描述】:

我试图弄清楚在输入和检测到不正确的值后如何清除和显示(重置)我清除的表单值。目前,当我发现一个不正确的输入时,它就在那里,即使我再次点击了输入按钮。任何帮助将不胜感激。

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

    }
}

}

【问题讨论】:

    标签: c# windows-mobile-5.0


    【解决方案1】:

    嗯。 . .所以我想通了。这只是我所做的一个逻辑错误:)

    namespace Mileage
    {
      public partial class Form2 : Form
      {
        private float beginMileage, endMileage, gallons, mpg;        
    
        public Form2()
        {
            InitializeComponent();
        }
    
        public void menuItem1_Click(object sender, EventArgs e)
        {
            beginMileage = float.Parse(this.textBox1.Text.Replace(" ", ""));
    
            endMileage = float.Parse(this.textBox2.Text.Replace(" ", ""));
    
            gallons = float.Parse(this.textBox3.Text.Replace(" ", ""));
    
            if((endMileage<0)||(beginMileage<0)||(gallons<0))
            {
                 this.label5.Text = String.Format("ERROR: One or more input(s) is negative.");
                 this.textBox1.Text = " ";
                 this.textBox2.Text = " ";
                 this.textBox3.Text = " ";   
            }
    
            else if ((endMileage == 0) || (gallons == 0))
            {
                this.label5.Text = String.Format("ERROR: The end mileage and/or gallon input is zero.");
                this.textBox1.Text = " ";
                this.textBox2.Text = " ";
                this.textBox3.Text = " ";                 
            }
    
            else if (endMileage < beginMileage)
            {
                this.label5.Text = String.Format("ERROR: End mileage is less than begining mileage.");
                this.textBox1.Text = " ";
                this.textBox2.Text = " ";
                this.textBox3.Text = " ";
    
            }
            else 
            {                               
                mpg = ((endMileage - beginMileage) / gallons);
                this.label5.Text = String.Format("{0}", mpg);
            }
    
        }
    
        public void menuItem2_Click(object sender, EventArgs e)
        {
            Application.Exit();            
    
        }
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多