
asp.net怎么编写加减乘除等于按钮
打开vs2010(或其它版本),创建一个windows窗体应用程序
在设计界面里,拖动button和textboxbutton是按钮,textbox用于显示。
然后分别点button1、button2.。。。。在右下角,把Text里的属性改成你要的数字或+-号。
界面弄好了。
要添加功能,就双击界面里的button进到代码页面Form1.cs*。
在里面写代码,运行调试时,点击该按钮,就会执行它对应的代码。
下面是我写的代码,你复制到你的代码页面里。
我是这样设的:button1 ----"+"号键
button2-----"="号键
button3----数字键1
button4----数字键2
你要弄对应,不然函数不对应。功能就不对应。
private void button1_Click(object sender, EventArgs e)//"+"号键
{
this.textBox1.Text = this.textBox1.Text + "+";
}
private void button3_Click(object sender, EventArgs e)//数字键1
{
string str1 = Convert.ToString(1);
this.textBox1.Text = this.textBox1.Text+str1;
}
private void button4_Click(object sender, EventArgs e)//数字键2
{
string str2 = Convert.ToString(2);
this.textBox1.Text = this.textBox1.Text+ str2;
}
private void button2_Click(object sender, EventArgs e)//"="号键
{
string str = this.textBox1.Text;
string[] strarray = str.Split(new char[] { '+' }, StringSplitOptions.RemoveEmptyEntries);
int[] a = new int[strarray.Length];
for (int i = 0; i < strarray.Length; i++)//把string数组的元素转换后赋给int数组
{
a[i] = Convert.ToInt32(strarray[i]);
}
int sum = 0;//求和
for (int i = 0; i < a.Length; i++)
{
sum = sum + a[i];
}
this.textBox2.Text = Convert.ToString(sum);
}
运行结果如下,鼠标点击键位。