想实现这个效果:TextBox3.Text = TextBox1.Text * TextBox2.Text,就是这三个文本框,我在文本框一和文本框二中输入数值,文本框三自动显示它们的乘积,谢谢!
我是这么做的:TextBox3.Text = (Convert.ToInt32(TextBox1.Text)*Convert.ToInt32(TextBox2.Text)).ToString();

解决方案 »

  1.   

    在textbox1和textbox2的textChange里面写.//双击控件
    最好给textbox1或textbox2的text属性初始化下.
    然后在两个textbox的textChange里把这句都写进去:
    TextBox3.Text = (Convert.ToInt32(TextBox1.Text)*Convert.ToInt32(TextBox2.Text)).ToString();
      

  2.   

    Convert.ToInt32不妥,最好是double,因为你不能保证你不输入小数。TextBox3.Text = (Convert.ToDouble(TextBox1.Text)*Convert.ToDouble(TextBox2.Text)).ToString();把这段代码放在TextBox1和TextBox2的文本改变时间中,另外最好先判断下文本框中是否有值
      

  3.   

    TextBox3.Text = (Convert.ToInt32(TextBox1.Text.Trim())*Convert.ToInt32(TextBox2.Text.Trim())).ToString();
    你上面的实现 方式最好是加个Trim()方法去掉空格,并且给TextBox1和 TextBox2加上验证,让它只能接收数字,使用验证控件就可以了
      

  4.   

    你要想TextBox3自动显示TextBox1和TextBox2的乘积,必须设置TextBox1和TextBox2的AutoPostback属性为true,设置了AutoPostBack为true之后就必须给TextBox1和TextBox2赋初始值,可以赋值为0这是一种实现方法,另外这样的效果最好用javascript实现,使用javascript不需要提交到服务器
      

  5.   

    需要javascript的实现方式就到我博客留言
      

  6.   

     private void textBox1_TextChanged(object sender, EventArgs e)
            {
                if (textBox1.Text == "" || textBox2.Text == "")
                {
                    
                    return; 
                }
                if (textBox2.Text != "")
                    textBox3.Text = (int.Parse(textBox1.Text) * int.Parse(textBox2.Text)).ToString();
                
                        }        private void textBox2_TextChanged(object sender, EventArgs e)
            {
                if (textBox1.Text == "" || textBox2.Text == "")
                {
                   
                    return;
                }
                if (textBox1.Text != "")
                    textBox3.Text = (int.Parse(textBox1.Text) * int.Parse(textBox2.Text)).ToString();
                
            }
      

  7.   

    判断输入的是否为数字:
      private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar)) && e.KeyChar != 13)
                {
                    MessageBox.Show("请输入数字");
                    e.Handled = true;
                }
            }        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
            {
                if ((e.KeyChar != 8 && !char.IsDigit(e.KeyChar)) && e.KeyChar != 13)
                {
                    MessageBox.Show("请输入数字");
                    e.Handled = true;
                }
            }