主页面设计
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace jisuanqi 11 { 12 public partial class Form1 : Form 13 { 14 public Form1() 15 { 16 InitializeComponent(); 17 } 18 19 20 double num1 = 0;//第一个输入数 21 double num2 = 0;//第二个输入数 22 double num3 = 0;//运算结果 23 double num4 = 0;//上次运算结果 24 double num5 = 0;//用于复制粘贴 25 string yunsuanfu;//运算符 26 bool p1=true;//判断是否为第一次输入 27 bool p2 = true;//判断是否为第一次输入 28 Button but; 29 30 31 32 private void button15_Click(object sender, EventArgs e)// 清除 33 { 34 textBox1.Text = ""; 35 num1 = 0; 36 num2 = 0; 37 num3 = 0; 38 num4 = 0; 39 label1.Text = ""; 40 label2.Text = ""; 41 label3.Text = ""; 42 } 43 private void button1_Click(object sender, EventArgs e)//输入1 44 { 45 if (p1 == true) 46 { 47 but = (Button)sender; 48 textBox1.Text += but.Text; 49 num1 = double.Parse(textBox1.Text); 50 label1.Text = num1.ToString(); 51 } 52 else 53 { 54 but = (Button)sender; 55 textBox1.Text += but.Text; 56 num2 = double.Parse(textBox1.Text); 57 label3.Text = num2.ToString(); 58 } 59 } 60 61 private void button2_Click(object sender, EventArgs e)//输入2 62 { 63 if (p1 == true) 64 { 65 but = (Button)sender; 66 textBox1.Text += but.Text; 67 num1 = double.Parse(textBox1.Text); 68 label1.Text = num1.ToString(); 69 } 70 else 71 { 72 but = (Button)sender; 73 textBox1.Text += but.Text; 74 num2 = double.Parse(textBox1.Text); 75 label3.Text = num2.ToString(); 76 } 77 } 78 79 private void button3_Click(object sender, EventArgs e)//输入3 80 { 81 if (p1 == true) 82 { 83 but = (Button)sender; 84 textBox1.Text += but.Text; 85 num1 = double.Parse(textBox1.Text); 86 label1.Text = num1.ToString(); 87 } 88 else 89 { 90 but = (Button)sender; 91 textBox1.Text += but.Text; 92 num2 = double.Parse(textBox1.Text); 93 label3.Text = num2.ToString(); 94 } 95 } 96 97 private void button4_Click(object sender, EventArgs e)//输入4 98 { 99 if (p1 == true)100 {101 but = (Button)sender;102 textBox1.Text += but.Text;103 num1 = double.Parse(textBox1.Text);104 label1.Text = num1.ToString();105 }106 else107 {108 but = (Button)sender;109 textBox1.Text += but.Text;110 num2 = double.Parse(textBox1.Text);111 label3.Text = num2.ToString();112 }113 }114 115 private void button5_Click(object sender, EventArgs e)//输入5116 {117 if (p1 == true)118 {119 but = (Button)sender;120 textBox1.Text += but.Text;121 num1 = double.Parse(textBox1.Text);122 label1.Text = num1.ToString();123 }124 else125 {126 but = (Button)sender;127 textBox1.Text += but.Text;128 num2 = double.Parse(textBox1.Text);129 label3.Text = num2.ToString();130 }131 }132 133 private void button6_Click(object sender, EventArgs e)//输入6134 {135 if (p1 == true)136 {137 but = (Button)sender;138 textBox1.Text += but.Text;139 num1 = double.Parse(textBox1.Text);140 label1.Text = num1.ToString();141 }142 else143 {144 but = (Button)sender;145 textBox1.Text += but.Text;146 num2 = double.Parse(textBox1.Text);147 label3.Text = num2.ToString();148 }149 }150 151 private void button7_Click(object sender, EventArgs e)//输入7152 {153 if (p1 == true)154 {155 but = (Button)sender;156 textBox1.Text += but.Text;157 num1 = double.Parse(textBox1.Text);158 label1.Text = num1.ToString();159 }160 else161 {162 but = (Button)sender;163 textBox1.Text += but.Text;164 num2 = double.Parse(textBox1.Text);165 label3.Text = num2.ToString();166 }167 }168 169 private void button8_Click(object sender, EventArgs e)//输入8170 {171 if (p1 == true)172 {173 but = (Button)sender;174 textBox1.Text += but.Text;175 num1 = double.Parse(textBox1.Text);176 label1.Text = num1.ToString();177 }178 else179 {180 but = (Button)sender;181 textBox1.Text += but.Text;182 num2 = double.Parse(textBox1.Text);183 label3.Text = num2.ToString();184 }185 }186 187 private void button9_Click(object sender, EventArgs e)//输入9188 {189 if (p1 == true)190 {191 but = (Button)sender;192 textBox1.Text += but.Text;193 num1 = double.Parse(textBox1.Text);194 label1.Text = num1.ToString();195 }196 else197 {198 but = (Button)sender;199 textBox1.Text += but.Text;200 num2 = double.Parse(textBox1.Text);201 label3.Text = num2.ToString();202 }203 }204 205 private void button16_Click(object sender, EventArgs e)//输入0206 {207 if (p1 == true)208 {209 but = (Button)sender;210 textBox1.Text += but.Text;211 num1 = double.Parse(textBox1.Text);212 label1.Text = num1.ToString();213 }214 else215 {216 but = (Button)sender;217 textBox1.Text += but.Text;218 num2 = double.Parse(textBox1.Text);219 label3.Text = num2.ToString();220 }221 }222 223 private void button17_Click(object sender, EventArgs e)//小数点224 {225 if (textBox1.Text != "")226 {227 if (p1 == true)228 {229 but = (Button)sender;230 textBox1.Text += but.Text;231 num1 = double.Parse(textBox1.Text);232 label1.Text = num1.ToString();233 }234 else235 {236 but = (Button)sender;237 textBox1.Text += but.Text;238 num2 = double.Parse(textBox1.Text);239 label3.Text = num2.ToString();240 }241 }242 else243 {244 textBox1.Text = "0.";245 }246 }247 248 private void button12_Click(object sender, EventArgs e)249 {250 yunsuanfu = "+";251 if (p2 == false)252 {253 label1.Text = num3.ToString();254 num3 = num1 + num2;255 }256 label2.Text = yunsuanfu.ToString();257 textBox1.Text = "";258 p1 = false;259 p2 = false;260 }261 262 private void button11_Click(object sender, EventArgs e)263 {264 yunsuanfu = "-";265 if (p2 == false)266 label1.Text = num3.ToString();267 label2.Text = yunsuanfu.ToString();268 textBox1.Text = "";269 p1 = false;270 p2 = true;271 }272 273 private void button10_Click(object sender, EventArgs e)274 {275 yunsuanfu = "*";276 if (p2 == false)277 label1.Text = num3.ToString();278 label2.Text = yunsuanfu.ToString();279 textBox1.Text = "";280 p1 = false;281 p2 = true;282 }283 284 private void button13_Click(object sender, EventArgs e)285 {286 yunsuanfu = "/";287 if (p2 == false)288 label1.Text = num3.ToString();289 label2.Text = yunsuanfu.ToString();290 textBox1.Text = "";291 p1 = false;292 p2 = true;293 }294 295 private void button14_Click(object sender, EventArgs e)296 {297 textBox1.Text = "";298 num1 = 0;299 num2 = 0;300 num3 = 0;301 label1.Text = "";302 label2.Text = "";303 label3.Text = "";304 }305 306 private void button18_Click(object sender, EventArgs e)307 {308 p1 = true;309 p2 = false;310 switch (yunsuanfu)311 {312 case "+":313 num3 = num1 + num2;314 break;315 case "-":316 num3 = num1 - num2;317 break;318 case "*":319 num3 = num1 * num2;320 break;321 case "/":322 num3 = num1 / num2;323 break;324 default:325 num3 = num1;326 break;327 }328 num1 = num3;329 num4 = num1;330 textBox1.Text = num3.ToString();331 332 }333 334 private void Form1_Load(object sender, EventArgs e)335 {336 337 }338 339 private void 标准型ToolStripMenuItem_Click(object sender, EventArgs e)340 {341 Form1 form1 = new Form1();342 form1.ShowDialog();343 }344 345 private void 进制转换ToolStripMenuItem_Click(object sender, EventArgs e)346 {347 Form2 form2 = new Form2();348 form2.ShowDialog();349 }350 351 private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)352 {353 if(textBox1.Text!="")354 {355 num5 = double.Parse(textBox1.Text);356 }357 }358 359 private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)360 {361 num3 = num5;362 label1.Text = num5.ToString();363 textBox1.Text = num5.ToString();364 }365 366 private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)367 {368 MessageBox.Show("姓名:相乾雄\n学号:1709312146","关于");369 }370 371 private void button19_Click(object sender, EventArgs e)372 {373 if (textBox1.Text.Length > 1)374 {375 string strTemp = textBox1.Text.Trim();376 textBox1.Text = strTemp.Substring(0, strTemp.Length - 1);377 num1 = double.Parse(textBox1.Text);378 label1.Text = textBox1.Text;379 }380 else381 {382 num1 = 0; ;383 textBox1.Text = "";384 }385 label1.Text = textBox1.Text;386 }387 }388 }
设计页面二进制转换
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace jisuanqi 11 { 12 public partial class Form2 : Form 13 { 14 public Form2() 15 { 16 InitializeComponent(); 17 } 18 19 double num1 = 0; 20 Button but; 21 22 private void button1_Click(object sender, EventArgs e) 23 { 24 but = (Button)sender; 25 textBox1.Text += but.Text; 26 } 27 28 private void button2_Click(object sender, EventArgs e) 29 { 30 but = (Button)sender; 31 textBox1.Text += but.Text; 32 } 33 34 private void button3_Click(object sender, EventArgs e) 35 { 36 but = (Button)sender; 37 textBox1.Text += but.Text; 38 } 39 40 private void button4_Click(object sender, EventArgs e) 41 { 42 but = (Button)sender; 43 textBox1.Text += but.Text; 44 } 45 46 private void button5_Click(object sender, EventArgs e) 47 { 48 but = (Button)sender; 49 textBox1.Text += but.Text; 50 } 51 52 private void button6_Click(object sender, EventArgs e) 53 { 54 but = (Button)sender; 55 textBox1.Text += but.Text; 56 } 57 58 private void button7_Click(object sender, EventArgs e) 59 { 60 but = (Button)sender; 61 textBox1.Text += but.Text; 62 } 63 64 private void button8_Click(object sender, EventArgs e) 65 { 66 but = (Button)sender; 67 textBox1.Text += but.Text; 68 } 69 70 private void button9_Click(object sender, EventArgs e) 71 { 72 but = (Button)sender; 73 textBox1.Text += but.Text; 74 } 75 76 private void button11_Click(object sender, EventArgs e)//清空 77 { 78 textBox1.Text = ""; 79 textBox2.Text = ""; 80 textBox3.Text = ""; 81 } 82 83 private void button10_Click(object sender, EventArgs e)//转换 84 { 85 textBox2.Text = System.Convert.ToString(Convert.ToInt32(textBox1.Text),2); 86 textBox3.Text = System.Convert.ToString(Convert.ToInt32(textBox1.Text), 16); 87 } 88 89 private void 标准型ToolStripMenuItem_Click(object sender, EventArgs e) 90 { 91 Form1 form1 = new Form1(); 92 form1.Show(); 93 } 94 95 private void 进制转换ToolStripMenuItem_Click(object sender, EventArgs e) 96 { 97 Form2 form2 = new Form2(); 98 form2.Show(); 99 }100 101 private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)102 {103 num1 = double.Parse(textBox1.Text);104 }105 106 private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)107 {108 textBox1.Text = num1.ToString();109 }110 111 private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)112 {113 MessageBox.Show("姓名:相乾雄\n学号:1709312146", "关于");114 }115 }116 }