想实现这个效果:TextBox3.Text = TextBox1.Text * TextBox2.Text,就是这三个文本框,我在文本框一和文本框二中输入数值,文本框三自动显示它们的乘积,谢谢!
我是这么做的:TextBox3.Text = (Convert.ToInt32(TextBox1.Text)*Convert.ToInt32(TextBox2.Text)).ToString();
我是这么做的:TextBox3.Text = (Convert.ToInt32(TextBox1.Text)*Convert.ToInt32(TextBox2.Text)).ToString();
解决方案 »
- C/S架构服务器配置
- Can't find PInvoke DLL 'hhpImgrSdk.dll'.
- 如何在WinForm中添加查询取消的功能
- 麻烦来看下生成动态数组的错误!!
- 100分求Jmail 4.3或 4.4 Pro文件,分不够还可以加!
- 请教高手:在C#.net中怎样将Html中的带合并单元格的Talbe导出成Execle文件里??
- 如何取得WebClient.DownloadFile(...)时的文件的真正类型,比如是text文本或图片?
- 关于C#中方法参数传递的问题
- 快崩溃了,项目在公司测试是很正常的,一拿到客户那里就出一大难的问题.都是提示数据库链接错误.高手帮忙看一下是什么问题啊~~~~~~~~~~~
- 能否在运行中改变web service的来源URL?
- VS自带的install经典问题求教
- 怎么把外部EXE封装进我的EXE中
最好给textbox1或textbox2的text属性初始化下.
然后在两个textbox的textChange里把这句都写进去:
TextBox3.Text = (Convert.ToInt32(TextBox1.Text)*Convert.ToInt32(TextBox2.Text)).ToString();
你上面的实现 方式最好是加个Trim()方法去掉空格,并且给TextBox1和 TextBox2加上验证,让它只能接收数字,使用验证控件就可以了
{
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();
}
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;
}
}