c#菜鸟问题

ztyx8x9 2012-05-17 01:24:12
两个文本框,textchange促发事件,当两个文本框中都为数字时两者相乘放到第三个文本框,求代码....
...全文
160 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
JinJJ1402 2012-05-17
  • 打赏
  • 举报
回复
建议楼上百度
xiangqianbo 2012-05-17
  • 打赏
  • 举报
回复
TextChange中看两个文本框中是不是有值,且是数字,是的话相乘赋值就完了呗!
Osiris4Net 2012-05-17
  • 打赏
  • 举报
回复
被乘数或乘数改变时应该作出同样的处理——求积,所以用同一个事件来描述一个处理会更合适。
Osiris4Net 2012-05-17
  • 打赏
  • 举报
回复
在窗体中摆三个TextBox,分别叫做txt被乘数,txt乘数,txt积……
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.txt被乘数.TextChanged += new EventHandler(被乘数或乘数_TextChanged);// 改变被乘数时触发事件
this.txt乘数.TextChanged += new EventHandler(被乘数或乘数_TextChanged);// 改变乘数时触发事件
}

void 被乘数或乘数_TextChanged(object sender, EventArgs e)
{
try
{
decimal 被乘数 = Convert.ToDecimal(this.txt被乘数.Text);
decimal 乘数 = Convert.ToDecimal(this.txt乘数.Text);
this.txt积.Text = (被乘数 * 乘数).ToString();
}
catch
{
this.txt积.Text = string.Empty;
}
}
}
}
shadan05 2012-05-17
  • 打赏
  • 举报
回复
这个问题你都要问?
llkaximoduo 2012-05-17
  • 打赏
  • 举报
回复

<div>
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true "></asp:TextBox>
*
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="true "></asp:TextBox>
=
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</div>



namespace WebApplication2
{
public partial class test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
int num1 = 0;
int num2 = 0;
protected void TextBox1_TextChanged(object sender, EventArgs e)
{

num1 = ConvertStringToInteger(TextBox1.Text.Trim());
num2 = ConvertStringToInteger(TextBox2.Text.Trim());
TextBox3.Text = (num1 * num2).ToString();
}

protected void TextBox2_TextChanged(object sender, EventArgs e)
{
num1 = ConvertStringToInteger(TextBox1.Text.Trim());
num2 = ConvertStringToInteger(TextBox2.Text.Trim());
TextBox3.Text = (num1 * num2).ToString();
}

private static int ConvertStringToInteger(string s)
{
int result = 0;
int.TryParse(s, out result);
return result;
}
}
}
llkaximoduo 2012-05-17
  • 打赏
  • 举报
回复
前台

<div>
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true "></asp:TextBox>
*
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="true "></asp:TextBox>
=
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</div>

cs页面

namespace WebApplication2
{
public partial class test1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
int num1 = 0;
int num2 = 0;
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TextBox1.Text.Trim()))
{
num1 = ConvertStringToInteger(TextBox1.Text.Trim());
}
if (!string.IsNullOrEmpty(TextBox2.Text.Trim()))
{
num2 = ConvertStringToInteger(TextBox2.Text.Trim());
}
TextBox3.Text = (num1 * num2).ToString();
}

protected void TextBox2_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(TextBox1.Text.Trim()))
{
num1 = ConvertStringToInteger(TextBox1.Text.Trim());
}
if (!string.IsNullOrEmpty(TextBox2.Text.Trim()))
{
num2 = ConvertStringToInteger(TextBox2.Text.Trim());
}
TextBox3.Text = (num1 * num2).ToString();
}

private static int ConvertStringToInteger(string s)
{
int result = 0;
int.TryParse(s, out result);
return result;
}
}
}




ztyx8x9 2012-05-17
  • 打赏
  • 举报
回复
不知道该怎么描述这个问题,你说的貌似度娘很神的样子

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧