![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
如何动态的在第3个TextBox中显示前两个TextBox中数字的乘积? 20
有3个TextBox,初始都为0,现在分别在前两个TextBox中输入数字,那么相乘的数字的结果就在第3个TextBox中显示出来了(不需要按BUTTON才返回结果),如...
有3个TextBox,初始都为0,现在分别在前两个TextBox中输入数字,那么相乘的数字的结果就在第3个TextBox中显示出来了(不需要按BUTTON才返回结果),如何做到啊?
展开
3个回答
展开全部
//TextBook1的数值变化时引起的事件处理程序
private void textBox1_TextChanged(object sender, EventArgs e)
{
double x1, x2, x3;
//if语句使修改数据时不出现异常
if (this.textBox1.Text != "" && this.textBox2 .Text!="")
{
x1 = double.Parse(this.textBox1.Text);
x2 = double.Parse(this.textBox2.Text);
x3 = x1 * x2;
this.textBox3.Text = x3.ToString();
}
else
this.textBox3.Text = "";
}
//添加TextBook2的数值变化时引起的事件处理程序,同TextBook1
展开全部
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "0";
textBox2.Text = "0";
textBox3.Text = "0";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text == "") return;
textBox3.Text = (float.Parse(textBox1.Text) * float.Parse(textBox2.Text)).ToString();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "") return;
textBox3.Text = (float.Parse(textBox1.Text) * float.Parse(textBox2.Text)).ToString();
}
{
textBox1.Text = "0";
textBox2.Text = "0";
textBox3.Text = "0";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text == "") return;
textBox3.Text = (float.Parse(textBox1.Text) * float.Parse(textBox2.Text)).ToString();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "") return;
textBox3.Text = (float.Parse(textBox1.Text) * float.Parse(textBox2.Text)).ToString();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用Text的Change事件就行了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询