C#解决报错问题

利用try catch语句

private void textBox1_TextChanged(object sender, EventArgs e)

        {   //文本框里面只能输入数字
            try 
            {
                
                c = Convert.ToDouble(textBox1.Text) ;
                d = Convert.ToInt32(c - 1.5);
              
                

            }

           //输入不是数字,自动清空,不会引发程序报错

            catch
            { 
                
                textBox1.Text = ("");
                
             
              }

猜你喜欢

转载自blog.csdn.net/wohongg/article/details/80091001
今日推荐