-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyCalculator.cs
65 lines (57 loc) · 1.58 KB
/
MyCalculator.cs
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
namespace SimpleCalculator
{
public partial class MyCalculator : Form
{
private int inputTag = 0;
public long LeftNum { set; get; }
public long RightNum { set; get; }
public long PrevResult { set; get; }
private MyMathOperator calculateMethod;
public MyMathOperator CalculateMethod
{
set
{
inputTag = (inputTag + 1) % 2;
calculateMethod = value;
}
get
{
return calculateMethod;
}
}
public MyCalculator()
{
InitializeComponent();
}
public bool IsLeftNum()
{
return inputTag == 0;
}
public bool IsRightNum()
{
return inputTag == 1;
}
private void MyCalculator_Load(object sender, EventArgs e)
{
}
private void BtnEnter_Click(object sender, EventArgs e)
{
// 输出答案
if (inputTag == 1) {
long result = CalculateMethod.Calculate(LeftNum, RightNum);
inputTag = (inputTag + 1) % 2;
LeftNum = 0;
RightNum = 0;
PrevResult = result;
DisplayTextBox.Text = result.ToString();
}
else
{
// 将之前的计算结果变成输入值
LeftNum = PrevResult;
PrevResult = 0;
DisplayTextBox.Text = LeftNum.ToString();
}
}
}
}