-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
157 lines (130 loc) · 4.17 KB
/
MainWindow.xaml.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Calculator
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Btn0_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "0";
}
private void Btn1_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "1";
}
private void Btn2_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "2";
}
private void Btn3_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "3";
}
private void Btn4_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "4";
}
private void Btn5_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "5";
}
private void Btn6_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "6";
}
private void Btn7_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "7";
}
private void Btn8_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "8";
}
private void Btn9_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "9";
}
private void BtnDiv_Click_1(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "/";
}
private void BtnMult_Click_1(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "*";
}
private void BtnSub_Click_1(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "-";
}
private void BtnAdd_Click_1(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + "+";
}
private void BtnEqu_Click_1(object sender, RoutedEventArgs e)
{
if (Disp.Text!="")
{
Type type = Type.GetTypeFromCLSID(Guid.Parse("0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC"));
dynamic obj = Activator.CreateInstance(type, false);
obj.Language = "javascript";
string str = null;
try
{
var result = obj.Eval(Disp.Text);
str = Convert.ToString(result);
Disp.Text = Disp.Text + "=" + str;
}
catch (SystemException)
{
Disp.Text = "Error";
}
}
}
private void BtnCE_Click(object sender, RoutedEventArgs e)
{
Disp.Text = "";
}
private void BtnSqrt_Click(object sender, RoutedEventArgs e)
{
double num;
var isDouble = double.TryParse(this.Disp.Text, out num);
if (isDouble)
{
this.Disp.Text =
string.Format(
"{0}{1} = {2}",
"\u221A",
this.Disp.Text,
Math.Round(Math.Sqrt(num), 2));
}
}
private void BtnPlusNeg_Click_1(object sender, RoutedEventArgs e)
{
Disp.Text = "-" + Disp.Text;
}
private void BtnDec_Click(object sender, RoutedEventArgs e)
{
Disp.Text = Disp.Text + ".";
}
}
}