本文介绍了C#.net中的税收计算错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



Hello,

private void textBox2_TextChanged(object sender, EventArgs e)
        {
            float t;
            float g;

            t = float.Parse(textBox3.Text);
            g = float.Parse(textBox10.Text);
            float j;

            j = g * (t / 100) + g;


            Convert.ToDecimal(textBox2.Text = j.ToString());
        }



这里输入字符串不正确textbox3.text中的格式错误如何解决帮助我......


Here input string is not correct format error in textbox3.text how to resolve Help me......

推荐答案

private void textBox2_TextChanged(object sender, EventArgs e)
    {
    float t;
    float g;
    if (!float.TryParse(textBox3.Text, out t))
        {
        MessageBox.Show("Please type a number in textbox 3!");
        return;
        }
    if (!float.TryParse(textBox10.Text, out g))
        {
        MessageBox.Show("Please type a number in textbox 10!");
        return;
        }

    float j = g * (t / 100) + g;
    string result = j.ToString();
    if (textBox2.Text != result)
        {
        textBox2.Text = result;
        }
    }



注意底部的位:如果你每次只设置TextBox2.Text的值,它会立即导致新事件发生!



并帮自己一个忙:停止使用控件的VS默认名称!将控件命名为描述用户使用它们的名称会使代码更加可靠和可读!




Notice the bit at the bottom: if you just set the value of TextBox2.Text each time, it will immediately cause a new event to occur!

And do yourself a favour: stop using VS default names for controls! Calling your controls a name that describes what the user uses them for makes your code much more reliable and readable!

textBox2  => tbTaxDue
textBox10 => tbTaxRate



等。


and so forth.



这篇关于C#.net中的税收计算错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:10