江西九江租车公司排行榜
672
2022-05-29
控件设置
拖动textbutton控件,用于显示
拖动Button控件,组成数字和符号键盘,
添加好后可以手动拖动控件调整大小,效果如下:
form标签源码为:
1
2
3
4
5
6
7
8
9
10
11
12
编写计算代码
public partial class WebForm1 : System.Web.UI.Page { static string num1 = "0", num2 = "0", total = "", sign = ""; // 数字1按钮 protected void btnone_Click(object sender, EventArgs e) { total += "1"; txtDisplay.Text = total; } // 数字2按钮 protected void btnTwo_Click(object sender, EventArgs e) { total += "2"; txtDisplay.Text = total; } // 数字3 按钮 protected void btnThree_Click(object sender, EventArgs e) { total += "3"; txtDisplay.Text = total; } // 加法按钮 protected void btnAdd_Click(object sender, EventArgs e) { if (sign.Length == 1) { Count(); num1 = txtDisplay.Text; sign = "+"; } else { num1 = txtDisplay.Text; txtDisplay.Text = ""; total = ""; sign = "+"; } } //减法按钮 protected void btnSubtract_Click(object sender, EventArgs e) { if (sign.Length == 1) { Count(); num1 = txtDisplay.Text; sign = "-"; } else { num1 = txtDisplay.Text; txtDisplay.Text = ""; total = ""; sign = "-"; } } // 等于按钮 protected void btnEqual_Click(object sender, EventArgs e) { Count(); } // 函数定义 protected void Count() { num2 = txtDisplay.Text; if (num2 == "") { num2 = "0"; } switch (sign) { case "+": txtDisplay.Text = (int.Parse(num1) + int.Parse(num2)).ToString(); num1 = "0"; num2 = "0"; total = ""; sign = ""; break; case "-": txtDisplay.Text = (int.Parse(num1) - int.Parse(num2)).ToString(); num1 = "0"; num2 = "0"; total = ""; sign = ""; break; } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
测试
ASP ASP.NET
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。