怎么实现textbox1,textbox2、、、失去焦点后他的自动求和加到textbox3里

解决方案 »

  1.   

    对,就是用Leave事件
    private void textBox1_Leave(object sender, System.EventArgs e)
    {
    double d=double.Parse(this.textBox1.Text)+double.Parse(this.textBox2.Text);
    this.textBox3.Text=d.ToString();
    }
      

  2.   

    调试了一下。。
    代码其实应该这样:
    private void textBox1_Leave(object sender, System.EventArgs e)
    {
    double d=0;
    if(this.textBox2.ContainsFocus==false)
    {
    d=double.Parse(this.textBox1.Text)+double.Parse(this.textBox2.Text);
    this.textBox3.Text=d.ToString();
    }
    } private void textBox2_Leave(object sender, System.EventArgs e)
    {
    double d=0;
    if(this.textBox1.ContainsFocus==false)
    {
    d=double.Parse(this.textBox1.Text)+double.Parse(this.textBox2.Text);
    this.textBox3.Text=d.ToString();
    }
    }