| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1146 人关注过本帖
标题:VS编程清空textbox出现错误,输入字符串的格式不正确。
只看楼主 加入收藏
haojiayong
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-2-3
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
VS编程清空textbox出现错误,输入字符串的格式不正确。
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Double F, Y, f, L, δ = 0, ΔL1, ΔL2, ΔL, Result ,a;
        String Flag;  


        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            F = Convert.ToDouble(textBox2.Text);

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            f = Convert.ToDouble(textBox3.Text);
            
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            L = Convert.ToDouble(textBox4.Text)*1000;
            
        }


        private void button1_Click(object sender, EventArgs e)
        {
            //string str = textBox1.Text;
            ΔL1 = (F * δ * Math.Pow(L, 2)) / (Math.Pow(f, 2) + F * δ * L);
            ΔL2 = (F * δ * Math.Pow(L, 2)) / (Math.Pow(f, 2) - F * δ * L);
            ΔL = ΔL1 + ΔL2;
            //a = F * δ * Math.Pow(L, 2);
            //Result = F + δ;
            MessageBox.Show(Convert.ToString(ΔL));
            //MessageBox.Show(Convert.ToString(ΔL1));
            //MessageBox.Show(Convert.ToString(ΔL2));
            //MessageBox.Show(Convert.ToString(ΔL));
        }


        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {


        }


        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 0x20) e.KeyChar = (char)0;  //禁止空格键
            //if (textBox3.Text.Trim() != "")
            if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return;   //处理负数
            if (e.KeyChar > 0x20)
            {
                try
                {
                    double.Parse(((TextBox)sender).Text + e.KeyChar.ToString());
                }
                catch
                {
                    e.KeyChar = (char)0;   //处理非法字符
                }
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 0x20) e.KeyChar = (char)0;  //禁止空格键
            //if (textBox2.Text.Trim() != "")
            if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return;   //处理负数
            if (e.KeyChar > 0x20)
            {
                try
                {
                    double.Parse(((TextBox)sender).Text + e.KeyChar.ToString());
                }
                catch
                {
                    e.KeyChar = (char)0;   //处理非法字符
                }
            }
        }

        private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 0x20) e.KeyChar = (char)0;  //禁止空格键
            //if (textBox4.Text.Trim() != "")
            if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return;   //处理负数
            if (e.KeyChar > 0x20)
            {
                try
                {
                    double.Parse(((TextBox)sender).Text + e.KeyChar.ToString());
                }
                catch
                {
                    e.KeyChar = (char)0;   //处理非法字符
                }
            }
        }
搜索更多相关主题的帖子: Text object sender void private 
2022-03-12 02:18
apull
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:三体星系
等 级:版主
威 望:216
帖 子:1509
专家分:9241
注 册:2010-3-16
收藏
得分:20 
清空直接用
textBox4.Text= ""
2022-03-12 19:30
快速回复:VS编程清空textbox出现错误,输入字符串的格式不正确。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016821 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved