view source
print?
001usingSystem;
002usingSystem.Collections.Generic;
003usingSystem.ComponentModel;
004usingSystem.Data;
005usingSystem.Drawing;
006usingSystem.Linq;
007usingSystem.Text;
008usingSystem.Windows.Forms;
009
010namespaceWindowsFormsApplication计算器
011{
012publicpartialclassForm1 : Form
013{
014publicForm1()
015{
016InitializeComponent();
017}
018doublesave = 0; stringbianji = " ";
019privatevoidForm1_Load(objectsender, EventArgs e)
020{
021
022}
023
024privatevoidbutton3_Click(objectsender, EventArgs e)
025{
026textBox1.Text += "3";
027}
028
029privatevoidbutton12_Click(objectsender, EventArgs e)
030{
031stringc = textBox1.Text;
032if(c.IndexOf("+") > 0)
033{
034intpos1 = c.IndexOf("+");
035stringa = c.Substring(0, pos1);
036stringb = c.Substring(pos1 + 1);
037doubles = Convert.ToDouble(a) + Convert.ToDouble(b);
038textBox1.Text = Convert.ToString(s);
039}
040if(c.IndexOf("-") > 0)
041{
042intpos1 = c.IndexOf("-");
043stringa = c.Substring(0, pos1);
044stringb = c.Substring(pos1 + 1);
045doubles = Convert.ToDouble(a) - Convert.ToDouble(b);
046textBox1.Text = Convert.ToString(s);
047}
048if(c.IndexOf("*") > 0)
049{
050intpos1 = c.IndexOf("*");
051stringa = c.Substring(0, pos1);
052stringb = c.Substring(pos1 + 1);
053doubles = Convert.ToDouble(a) * Convert.ToDouble(b);
054textBox1.Text = Convert.ToString(s);
055}
056if(c.IndexOf("/") > 0 && c.IndexOf("%") < 0)
057{
058intpos1 = c.IndexOf("/");
059stringa = c.Substring(0, pos1);
060stringb = c.Substring(pos1 + 1);
061doubles = Convert.ToDouble(a) / Convert.ToDouble(b);
062textBox1.Text = Convert.ToString(s);
063}
064if(c.IndexOf("/") > 0 && c.IndexOf("%") > 0)
065{
066intpos1 = c.IndexOf("/");
067intpos2 = c.IndexOf("%");
068stringa = c.Substring(0, pos1);
069stringb = c.Substring(pos1 + 1, pos2-pos1-1);
070doubles = (Convert.ToDouble(a) / Convert.ToDouble(b)) * 100;
071textBox1.Text = Convert.ToString(s);
072}
073
074
075}
076
077privatevoidtextBox1_TextChanged(objectsender, EventArgs e)
078{
079
080}
081
082privatevoidbutton1_Click(objectsender, EventArgs e)
083{
084textBox1.Text += "1";
085}
086
087privatevoidbutton2_Click(objectsender, EventArgs e)
088{
089textBox1.Text += "2";
090}
091
092privatevoidbutton4_Click(objectsender, EventArgs e)
093{
094textBox1.Text += "4";
095}
096
097privatevoidbutton5_Click(objectsender, EventArgs e)
098{
099textBox1.Text += "5";
100}
101
102privatevoidbutton6_Click(objectsender, EventArgs e)
103{
104textBox1.Text += "6";
105}
106
107privatevoidbutton7_Click(objectsender, EventArgs e)
108{
109textBox1.Text += "7";
110}
111
112privatevoidbutton8_Click(objectsender, EventArgs e)
113{
114textBox1.Text += "8";
115}
116
117privatevoidbutton9_Click(objectsender, EventArgs e)
118{
119textBox1.Text += "9";
120}
121
122privatevoidbutton10_Click(objectsender, EventArgs e)
123{
124textBox1.Text += "0";
125}
126
127privatevoidbutton11_Click(objectsender, EventArgs e)
128{
129textBox1.Text += ".";
130}
131
132privatevoidbutton16_Click(objectsender, EventArgs e)
133{
134textBox1.Text += "/";
135}
136
137privatevoidbutton15_Click(objectsender, EventArgs e)
138{
139textBox1.Text += "*";
140}
141
142privatevoidbutton14_Click(objectsender, EventArgs e)
143{
144textBox1.Text += "-";
145}
146
147privatevoidbutton13_Click(objectsender, EventArgs e)
148{
149textBox1.Text += "+";
150
151}
152
153privatevoidbutton17_Click(objectsender, EventArgs e)
154{
155textBox1.Text = "";
156
157
158
159}
160
161privatevoid查看ToolStripMenuItem_Click(objectsender, EventArgs e)
166privatevoid编辑ToolStripMenuItem_Click(objectsender, EventArgs e)
171privatevoid帮助ToolStripMenuItem_Click(objectsender, EventArgs e)
176privatevoid历史记录ToolStripMenuItem_Click(objectsender, EventArgs e)
177{
178
179}
180
181privatevoidstatusStrip1_ItemClicked(objectsender, ToolStripItemClickedEventArgs e)
182{
183
184}
185
186privatevoidopenFileDialog1_FileOk(objectsender, CancelEventArgs e)
187{
188
189}
190
191privatevoid查看ToolStripMenuItem_Click_1(objectsender, EventArgs e)
192{
193
194}
195
196privatevoidbutton20_Click(objectsender, EventArgs e)
197{
198if(textBox1.Text.Length > 0)
199{
200textBox1.Text = "1/"+ textBox1.Text;
201stringc = textBox1.Text;
202intpos1 = c.IndexOf("/");
203stringa = "1";
204stringb = c.Substring(pos1 + 1);
205doubles = Convert.ToDouble(a) / Convert.ToDouble(b);
206textBox1.Text = Convert.ToString(s);
207}
208
209}
210
211privatevoidbutton18_Click(objectsender, EventArgs e)
212{
213if(textBox1.Text.Length > 0)
214{
215textBox1.Text = "√"+ textBox1.Text;
216stringc = textBox1.Text;
217intpos1 = c.IndexOf("√");
218stringb = c.Substring(pos1 + 1);
219doubles = Math.Sqrt(Convert.ToDouble(b));
220textBox1.Text = Convert.ToString(s);
221}
222
223}
224
225privatevoidbutton19_Click(objectsender, EventArgs e)
226{
227textBox1.Text += "%";
228
229
230
231
232}
233
234privatevoid编辑EToolStripMenuItem_Click(objectsender, EventArgs e)
235{
236
237}
238
239privatevoidbutton27_Click(objectsender, EventArgs e)
240{
241if(textBox1.Text.Length > 0)
242{
243stringc = textBox1.Text;
244intl = c.Length;
245stringc1 = c.Remove(l - 1, 1);
246textBox1.Text = c1;
247}
248}
249
250privatevoidbutton21_Click(objectsender, EventArgs e)
251{
252if(textBox1.Text.Length > 0)
253{
254stringc = textBox1.Text;
255doublec1 = Convert.ToDouble(c);
256c1 = c1 * (-1);
257textBox1.Text = Convert.ToString(c1);
258}
259}
260
261privatevoidbutton22_Click(objectsender, EventArgs e)
262{
263save = 0;
264
265}
266
267privatevoidbutton24_Click(objectsender, EventArgs e)
268{
269if(textBox1.Text.Length > 0)
270{
271doublems = Convert.ToDouble(textBox1.Text);
272save = ms;
273}
274}
275
276privatevoidbutton23_Click(objectsender, EventArgs e)
277{
278doublemr = save;
279textBox1.Text = Convert.ToString(mr);
280}
281
282privatevoidbutton25_Click(objectsender, EventArgs e)
283{
284if(textBox1.Text.Length > 0)
285{ save = save + Convert.ToDouble(textBox1.Text); }
286}
287
288privatevoidbutton26_Click(objectsender, EventArgs e)
289{
290if(textBox1.Text.Length > 0)
291{ save = save - Convert.ToDouble(textBox1.Text); }
292}
293
294privatevoid复制ToolStripMenuItem_Click(objectsender, EventArgs e)
295{
296stringfuzhi = textBox1.Text;
297bianji = fuzhi;
298}
299
300privatevoid粘贴ToolStripMenuItem_Click(objectsender, EventArgs e)
301{
302stringniantie = bianji;
303textBox1.Text = bianji;
304}
305
306
307
308
309}
310
311}