实例介绍
【实例简介】
【实例截图】
【核心代码】
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 | using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace 多功能计算机器 { public class Form : System.Windows.Forms.Form { private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox expressBox; private System.ComponentModel.Container components = null ; //***往下为自已定义的变量*** //定义存放运算符(包括:' ','-',...,'sin',...,'arcsin',...,'(',...等)及其特性的数据结构 public struct opTable //定义存放运算符及其优先级和单双目的结构 { public string op; //用于存放运算符 op为oprater的简写 public int code; //用存放运算符的优先级 public char grade; //用于判断存放的运算符是单目还是双目 } public opTable[] opchTbl= new opTable[19]; //用于存放制定好的运算符及其特性(优先级和单双目)的运算符表,其初始化在方法Initialize()中 public opTable[] operateStack= new opTable[30]; //用于存放从键盘扫描的运算符的栈 //定义优先级列表 1,2,3,4,5,6,7,8,9, public int []osp= new int [19]{6,6,6,6,6,6,6,6,6,6,6,5,3,3,2,2,7,0,1}; //数组中元素依次为: "sin","cos","tan","cot","arcsin","arccos","arctan","sec","csc","ln","^","*","/"," ","-","(",")","" 的栈外(因为有的运算符是从右向左计算,有的是从左往右计算,用内外优先级可以限制其执行顺序)优先级 public int []isp= new int [18]{5,5,5,5,5,5,5,5,5,5,5,4,3,3,2,2,1,1}; //数组中元素依次为: "sin","cos","tan","cot","arcsin","arccos","arctan","sec","csc","ln","^","*","/"," ","-","(" ,"end" 的栈内(因为有的运算符是从右向左计算,有的是从左往右计算,用内外优先级可以限制其执行顺序)优先级 //定义存放从键盘扫描的数据的栈 public double []dataStack= new double [30]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //定义表态指针 public int opTop=-1; //指向存放(从键盘扫描的)运算符栈的指针 public int dataTop=-1; //指向存放(从键盘扫描的)数据栈指针 //定义存放从键盘输入的起始字符串 public string startString; public int startTop=0; public double variableX=0; public double variableY=0; const double PI=3.1415926; int number=1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.Windows.Forms.Button button5; private System.Windows.Forms.Button button6; private System.Windows.Forms.Button button7; private System.Windows.Forms.Button button8; private System.Windows.Forms.Button button9; private System.Windows.Forms.Button button10; private System.Windows.Forms.Button button11; private System.Windows.Forms.Button button12; private System.Windows.Forms.Button button13; private System.Windows.Forms.Button button14; private System.Windows.Forms.Button button15; private System.Windows.Forms.Button button16; private System.Windows.Forms.Button button17; private System.Windows.Forms.Button button18; private System.Windows.Forms.Button button19; private System.Windows.Forms.Button button20; private System.Windows.Forms.Button button21; private System.Windows.Forms.Button button22; private System.Windows.Forms.Button button23; private System.Windows.Forms.Button button24; private System.Windows.Forms.Button button25; private System.Windows.Forms.Button button26; private System.Windows.Forms.Button button27; private System.Windows.Forms.Button button28; private System.Windows.Forms.Button button29; private System.Windows.Forms.Button button30; private System.Windows.Forms.Button button31; private System.Windows.Forms.Button button32; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox endbox; private System.Windows.Forms.Button button33; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox endList; private System.Windows.Forms.Button button34; private System.Windows.Forms.Button button35; private System.Windows.Forms.Button button40; public int startTopMoveCount=0; //******* //int x=0; #region Windows Form Designer generated code public Form() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if ( disposing ) { if (components != null ) { components.Dispose(); } } base .Dispose( disposing ); } #endregion #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this .expressBox = new System.Windows.Forms.TextBox(); this .label2 = new System.Windows.Forms.Label(); this .button1 = new System.Windows.Forms.Button(); this .button2 = new System.Windows.Forms.Button(); this .button3 = new System.Windows.Forms.Button(); this .button4 = new System.Windows.Forms.Button(); this .button5 = new System.Windows.Forms.Button(); this .button6 = new System.Windows.Forms.Button(); this .button7 = new System.Windows.Forms.Button(); this .button8 = new System.Windows.Forms.Button(); this .button9 = new System.Windows.Forms.Button(); this .button10 = new System.Windows.Forms.Button(); this .button11 = new System.Windows.Forms.Button(); this .button12 = new System.Windows.Forms.Button(); this .button13 = new System.Windows.Forms.Button(); this .button14 = new System.Windows.Forms.Button(); this .button15 = new System.Windows.Forms.Button(); this .button16 = new System.Windows.Forms.Button(); this .button17 = new System.Windows.Forms.Button(); this .button18 = new System.Windows.Forms.Button(); this .button19 = new System.Windows.Forms.Button(); this .button20 = new System.Windows.Forms.Button(); this .button21 = new System.Windows.Forms.Button(); this .button22 = new System.Windows.Forms.Button(); this .button23 = new System.Windows.Forms.Button(); this .button24 = new System.Windows.Forms.Button(); this .button25 = new System.Windows.Forms.Button(); this .button26 = new System.Windows.Forms.Button(); this .button27 = new System.Windows.Forms.Button(); this .button28 = new System.Windows.Forms.Button(); this .button29 = new System.Windows.Forms.Button(); this .button30 = new System.Windows.Forms.Button(); this .button31 = new System.Windows.Forms.Button(); this .button32 = new System.Windows.Forms.Button(); this .label1 = new System.Windows.Forms.Label(); this .endbox = new System.Windows.Forms.TextBox(); this .button33 = new System.Windows.Forms.Button(); this .endList = new System.Windows.Forms.TextBox(); this .label3 = new System.Windows.Forms.Label(); this .button34 = new System.Windows.Forms.Button(); this .button35 = new System.Windows.Forms.Button(); this .button40 = new System.Windows.Forms.Button(); this .SuspendLayout(); // // expressBox // this .expressBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this .expressBox.Location = new System.Drawing.Point(112, 32); this .expressBox.Name = "expressBox" ; this .expressBox.Size = new System.Drawing.Size(288, 21); this .expressBox.TabIndex = 0; this .expressBox.Text = "" ; this .expressBox.TextChanged = new System.EventHandler( this .expressBox_TextChanged); // // label2 // this .label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this .label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this .label2.Location = new System.Drawing.Point(16, 32); this .label2.Name = "label2" ; this .label2.Size = new System.Drawing.Size(88, 24); this .label2.TabIndex = 6; this .label2.Text = "请输入表达式:" ; this .label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this .label2.Click = new System.EventHandler( this .label2_Click); // // button1 // this .button1.ForeColor = System.Drawing.SystemColors.HotTrack; this .button1.Location = new System.Drawing.Point(216, 288); this .button1.Name = "button1" ; this .button1.Size = new System.Drawing.Size(32, 23); this .button1.TabIndex = 8; this .button1.Text = "1" ; this .button1.Click = new System.EventHandler( this .button1_Click_1); // // button2 // this .button2.ForeColor = System.Drawing.SystemColors.HotTrack; this .button2.Location = new System.Drawing.Point(216, 248); this .button2.Name = "button2" ; this .button2.Size = new System.Drawing.Size(32, 23); this .button2.TabIndex = 9; this .button2.Text = "4" ; this .button2.Click = new System.EventHandler( this .button2_Click_1); // // button3 // this .button3.ForeColor = System.Drawing.SystemColors.HotTrack; this .button3.Location = new System.Drawing.Point(328, 288); this .button3.Name = "button3" ; this .button3.Size = new System.Drawing.Size(32, 23); this .button3.TabIndex = 10; this .button3.Text = "3" ; this .button3.Click = new System.EventHandler( this .button3_Click); // // button4 // this .button4.ForeColor = System.Drawing.SystemColors.HotTrack; this .button4.Location = new System.Drawing.Point(272, 288); this .button4.Name = "button4" ; this .button4.Size = new System.Drawing.Size(32, 23); this .button4.TabIndex = 11; this .button4.Text = "2" ; this .button4.Click = new System.EventHandler( this .button4_Click); // // button5 // this .button5.ForeColor = System.Drawing.SystemColors.HotTrack; this .button5.Location = new System.Drawing.Point(272, 248); this .button5.Name = "button5" ; this .button5.Size = new System.Drawing.Size(32, 23); this .button5.TabIndex = 12; this .button5.Text = "5" ; this .button5.Click = new System.EventHandler( this .button5_Click); // // button6 // this .button6.ForeColor = System.Drawing.SystemColors.HotTrack; this .button6.Location = new System.Drawing.Point(328, 248); this .button6.Name = "button6" ; this .button6.Size = new System.Drawing.Size(32, 23); this .button6.TabIndex = 13; this .button6.Text = "6" ; this .button6.Click = new System.EventHandler( this .button6_Click); // // button7 // this .button7.ForeColor = System.Drawing.SystemColors.HotTrack; this .button7.Location = new System.Drawing.Point(328, 208); this .button7.Name = "button7" ; this .button7.Size = new System.Drawing.Size(32, 23); this .button7.TabIndex = 14; this .button7.Text = "9" ; this .button7.Click = new System.EventHandler( this .button7_Click); // // button8 // this .button8.ForeColor = System.Drawing.SystemColors.HotTrack; this .button8.Location = new System.Drawing.Point(272, 208); this .button8.Name = "button8" ; this .button8.Size = new System.Drawing.Size(32, 23); this .button8.TabIndex = 15; this .button8.Text = "8" ; this .button8.Click = new System.EventHandler( this .button8_Click); // // button9 // this .button9.ForeColor = System.Drawing.SystemColors.HotTrack; this .button9.Location = new System.Drawing.Point(216, 208); this .button9.Name = "button9" ; this .button9.Size = new System.Drawing.Size(32, 23); this .button9.TabIndex = 16; this .button9.Text = "7" ; this .button9.Click = new System.EventHandler( this .button9_Click); // // button10 // this .button10.ForeColor = System.Drawing.SystemColors.HotTrack; this .button10.Location = new System.Drawing.Point(216, 328); this .button10.Name = "button10" ; this .button10.Size = new System.Drawing.Size(32, 23); this .button10.TabIndex = 17; this .button10.Text = "0" ; this .button10.Click = new System.EventHandler( this .button10_Click); // // button11 // this .button11.ForeColor = System.Drawing.SystemColors.HotTrack; this .button11.Location = new System.Drawing.Point(272, 328); this .button11.Name = "button11" ; this .button11.Size = new System.Drawing.Size(32, 23); this .button11.TabIndex = 18; this .button11.Text = "DEL" ; this .button11.Click = new System.EventHandler( this .button11_Click); // // button12 // this .button12.ForeColor = System.Drawing.SystemColors.HotTrack; this .button12.Location = new System.Drawing.Point(384, 248); this .button12.Name = "button12" ; this .button12.Size = new System.Drawing.Size(32, 23); this .button12.TabIndex = 19; this .button12.Text = "*" ; this .button12.Click = new System.EventHandler( this .button12_Click); // // button13 // this .button13.ForeColor = System.Drawing.SystemColors.HotTrack; this .button13.Location = new System.Drawing.Point(432, 248); this .button13.Name = "button13" ; this .button13.Size = new System.Drawing.Size(32, 23); this .button13.TabIndex = 20; this .button13.Text = "/" ; this .button13.Click = new System.EventHandler( this .button13_Click); // // button14 // this .button14.ForeColor = System.Drawing.SystemColors.HotTrack; this .button14.Location = new System.Drawing.Point(384, 288); this .button14.Name = "button14" ; this .button14.Size = new System.Drawing.Size(32, 23); this .button14.TabIndex = 21; this .button14.Text = " " ; this .button14.Click = new System.EventHandler( this .button14_Click); // // button15 // this .button15.ForeColor = System.Drawing.SystemColors.HotTrack; this .button15.Location = new System.Drawing.Point(432, 288); this .button15.Name = "button15" ; this .button15.Size = new System.Drawing.Size(32, 23); this .button15.TabIndex = 22; this .button15.Text = "-" ; this .button15.Click = new System.EventHandler( this .button15_Click); // // button16 // this .button16.BackColor = System.Drawing.SystemColors.InactiveCaption; this .button16.ForeColor = System.Drawing.SystemColors.HotTrack; this .button16.Location = new System.Drawing.Point(24, 208); this .button16.Name = "button16" ; this .button16.Size = new System.Drawing.Size(32, 23); this .button16.TabIndex = 23; this .button16.Text = "Sin" ; this .button16.Click = new System.EventHandler( this .button16_Click); // // button17 // this .button17.ForeColor = System.Drawing.SystemColors.HotTrack; this .button17.Location = new System.Drawing.Point(24, 248); this .button17.Name = "button17" ; this .button17.Size = new System.Drawing.Size(32, 23); this .button17.TabIndex = 24; this .button17.Text = "Cos" ; this .button17.Click = new System.EventHandler( this .button17_Click); // // button18 // this .button18.ForeColor = System.Drawing.SystemColors.HotTrack; this .button18.Location = new System.Drawing.Point(24, 288); this .button18.Name = "button18" ; this .button18.Size = new System.Drawing.Size(32, 23); this .button18.TabIndex = 25; this .button18.Text = "Tan" ; this .button18.Click = new System.EventHandler( this .button18_Click); // // button19 // this .button19.ForeColor = System.Drawing.SystemColors.HotTrack; this .button19.Location = new System.Drawing.Point(24, 328); this .button19.Name = "button19" ; this .button19.Size = new System.Drawing.Size(32, 23); this .button19.TabIndex = 26; this .button19.Text = "Cot" ; this .button19.Click = new System.EventHandler( this .button19_Click); // // button20 // this .button20.ForeColor = System.Drawing.SystemColors.HotTrack; this .button20.Location = new System.Drawing.Point(64, 208); this .button20.Name = "button20" ; this .button20.Size = new System.Drawing.Size(56, 23); this .button20.TabIndex = 27; this .button20.Text = "ArcSin" ; this .button20.Click = new System.EventHandler( this .button20_Click); // // button21 // this .button21.ForeColor = System.Drawing.SystemColors.HotTrack; this .button21.Location = new System.Drawing.Point(64, 248); this .button21.Name = "button21" ; this .button21.Size = new System.Drawing.Size(56, 23); this .button21.TabIndex = 28; this .button21.Text = "ArcCos" ; this .button21.Click = new System.EventHandler( this .button21_Click); // // button22 // this .button22.ForeColor = System.Drawing.SystemColors.HotTrack; this .button22.Location = new System.Drawing.Point(64, 288); this .button22.Name = "button22" ; this .button22.Size = new System.Drawing.Size(56, 23); this .button22.TabIndex = 29; this .button22.Text = "ArcTan" ; this .button22.Click = new System.EventHandler( this .button22_Click); // // button23 // this .button23.ForeColor = System.Drawing.SystemColors.HotTrack; this .button23.Location = new System.Drawing.Point(64, 328); this .button23.Name = "button23" ; this .button23.Size = new System.Drawing.Size(56, 23); this .button23.TabIndex = 30; this .button23.Text = "ArcCot" ; this .button23.Click = new System.EventHandler( this .button23_Click); // // button24 // this .button24.ForeColor = System.Drawing.SystemColors.HotTrack; this .button24.Location = new System.Drawing.Point(136, 208); this .button24.Name = "button24" ; this .button24.Size = new System.Drawing.Size(32, 23); this .button24.TabIndex = 31; this .button24.Text = "Sec" ; this .button24.Click = new System.EventHandler( this .button24_Click); // // button25 // this .button25.ForeColor = System.Drawing.SystemColors.HotTrack; this .button25.Location = new System.Drawing.Point(136, 248); this .button25.Name = "button25" ; this .button25.Size = new System.Drawing.Size(32, 23); this .button25.TabIndex = 32; this .button25.Text = "Csc" ; this .button25.Click = new System.EventHandler( this .button25_Click); // // button26 // this .button26.ForeColor = System.Drawing.SystemColors.HotTrack; this .button26.Location = new System.Drawing.Point(136, 288); this .button26.Name = "button26" ; this .button26.Size = new System.Drawing.Size(32, 23); this .button26.TabIndex = 33; this .button26.Text = "Ln" ; this .button26.Click = new System.EventHandler( this .button26_Click); // // button27 // this .button27.Font = new System.Drawing.Font( "宋体" , 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this .button27.ForeColor = System.Drawing.SystemColors.HotTrack; this .button27.Location = new System.Drawing.Point(320, 328); this .button27.Name = "button27" ; this .button27.Size = new System.Drawing.Size(48, 23); this .button27.TabIndex = 34; this .button27.Text = "次方" ; this .button27.Click = new System.EventHandler( this .button27_Click); // // button28 // this .button28.ForeColor = System.Drawing.SystemColors.HotTrack; this .button28.Location = new System.Drawing.Point(432, 208); this .button28.Name = "button28" ; this .button28.Size = new System.Drawing.Size(32, 23); this .button28.TabIndex = 35; this .button28.Text = ")" ; this .button28.Click = new System.EventHandler( this .button28_Click); // // button29 // this .button29.ForeColor = System.Drawing.SystemColors.HotTrack; this .button29.Location = new System.Drawing.Point(384, 208); this .button29.Name = "button29" ; this .button29.Size = new System.Drawing.Size(32, 23); this .button29.TabIndex = 36; this .button29.Text = "(" ; this .button29.Click = new System.EventHandler( this .button29_Click); // // button30 // this .button30.Font = new System.Drawing.Font( "宋体" , 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134))); this .button30.ForeColor = System.Drawing.SystemColors.HotTrack; this .button30.Location = new System.Drawing.Point(384, 328); this .button30.Name = "button30" ; this .button30.Size = new System.Drawing.Size(80, 23); this .button30.TabIndex = 37; this .button30.Text = "==" ; this .button30.Click = new System.EventHandler( this .button30_Click); // // button31 // this .button31.BackColor = System.Drawing.SystemColors.InactiveCaption; this .button31.ForeColor = System.Drawing.Color.Black; this .button31.Location = new System.Drawing.Point(328, 168); this .button31.Name = "button31" ; this .button31.Size = new System.Drawing.Size(96, 23); this .button31.TabIndex = 38; this .button31.Text = "Back Space" ; this .button31.Click = new System.EventHandler( this .button31_Click); // // button32 // this .button32.BackColor = System.Drawing.SystemColors.InactiveCaptionText; this .button32.ForeColor = System.Drawing.SystemColors.ControlText; this .button32.Location = new System.Drawing.Point(432, 168); this .button32.Name = "button32" ; this .button32.Size = new System.Drawing.Size(32, 23); this .button32.TabIndex = 39; this .button32.Text = "CE" ; this .button32.Click = new System.EventHandler( this .button32_Click); // // label1 // this .label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this .label1.Location = new System.Drawing.Point(40, 72); this .label1.Name = "label1" ; this .label1.Size = new System.Drawing.Size(64, 20); this .label1.TabIndex = 40; this .label1.Text = "计算结果:" ; this .label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // endbox // this .endbox.Anchor = System.Windows.Forms.AnchorStyles.Left; this .endbox.Location = new System.Drawing.Point(112, 72); this .endbox.Name = "endbox" ; this .endbox.Size = new System.Drawing.Size(136, 21); this .endbox.TabIndex = 41; this .endbox.Text = "0.000000" ; // // button33 // this .button33.ForeColor = System.Drawing.SystemColors.HotTrack; this .button33.Location = new System.Drawing.Point(136, 328); this .button33.Name = "button33" ; this .button33.Size = new System.Drawing.Size(32, 23); this .button33.TabIndex = 42; this .button33.Text = "Л" ; this .button33.Click = new System.EventHandler( this .button33_Click); // // endList // this .endList.Location = new System.Drawing.Point(112, 112); this .endList.Multiline = true ; this .endList.Name = "endList" ; this .endList.Size = new System.Drawing.Size(352, 21); this .endList.TabIndex = 43; this .endList.Tag = "ff" ; this .endList.Text = "" ; this .endList.TextChanged = new System.EventHandler( this .endList_TextChanged); // // label3 // this .label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this .label3.Location = new System.Drawing.Point(40, 112); this .label3.Name = "label3" ; this .label3.Size = new System.Drawing.Size(64, 20); this .label3.TabIndex = 44; this .label3.Text = "结果列表:" ; this .label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this .label3.Click = new System.EventHandler( this .label3_Click); // // button34 // this .button34.ForeColor = System.Drawing.SystemColors.ControlText; this .button34.Location = new System.Drawing.Point(24, 168); this .button34.Name = "button34" ; this .button34.Size = new System.Drawing.Size(96, 23); this .button34.TabIndex = 45; this .button34.Text = "清除结果列表" ; this .button34.Click = new System.EventHandler( this .button34_Click); // // button35 // this .button35.Location = new System.Drawing.Point(408, 72); this .button35.Name = "button35" ; this .button35.Size = new System.Drawing.Size(56, 23); this .button35.TabIndex = 46; this .button35.Text = "帮助" ; this .button35.Click = new System.EventHandler( this .button35_Click); // // button40 // this .button40.Location = new System.Drawing.Point(408, 32); this .button40.Name = "button40" ; this .button40.Size = new System.Drawing.Size(56, 23); this .button40.TabIndex = 54; this .button40.Text = "重写" ; this .button40.Click = new System.EventHandler( this .button40_Click); // // Form // this .AcceptButton = this .button30; this .AutoScaleBaseSize = new System.Drawing.Size(6, 14); this .BackColor = System.Drawing.SystemColors.InactiveCaption; this .ClientSize = new System.Drawing.Size(488, 390); this .Controls.Add( this .button40); this .Controls.Add( this .button35); this .Controls.Add( this .button34); this .Controls.Add( this .label3); this .Controls.Add( this .endList); this .Controls.Add( this .button33); this .Controls.Add( this .endbox); this .Controls.Add( this .label1); this .Controls.Add( this .button32); this .Controls.Add( this .button31); this .Controls.Add( this .button30); this .Controls.Add( this .button29); this .Controls.Add( this .button28); this .Controls.Add( this .button27); this .Controls.Add( this .button26); this .Controls.Add( this .button25); this .Controls.Add( this .button24); this .Controls.Add( this .button23); this .Controls.Add( this .button22); this .Controls.Add( this .button21); this .Controls.Add( this .button20); this .Controls.Add( this .button19); this .Controls.Add( this .button18); this .Controls.Add( this .button17); this .Controls.Add( this .button16); this .Controls.Add( this .button15); this .Controls.Add( this .button14); this .Controls.Add( this .button13); this .Controls.Add( this .button12); this .Controls.Add( this .button11); this .Controls.Add( this .button10); this .Controls.Add( this .button9); this .Controls.Add( this .button8); this .Controls.Add( this .button7); this .Controls.Add( this .button6); this .Controls.Add( this .button5); this .Controls.Add( this .button4); this .Controls.Add( this .button3); this .Controls.Add( this .button2); this .Controls.Add( this .button1); this .Controls.Add( this .label2); this .Controls.Add( this .expressBox); this .MaximizeBox = false ; this .Name = "Form" ; this .Text = "多功能计算器" ; this .Load = new System.EventHandler( this .Form1_Load); this .ResumeLayout( false ); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run( new Form()); } private void Form1_Load( object sender, System.EventArgs e) { } private void Form_MouseMove( object sender, System.Windows.Forms.MouseEventArgs e) { //label3.Text="X: " e.X.ToString() " ,Y: " e.Y.ToString(); } /* private void button1_Click( object sender, System.EventArgs e) { StartExcute(); } private void button2_Click( object sender, System.EventArgs e) { Application.Exit(); }*/ private void expressBox_TextChanged( object sender, System.EventArgs e) { } public void InitializeOpchTblStack() //制定运算符及其特性(优先级和单双目)的运算符表 { //public int[]osp={6,6,6,6,6,6,6,6,6,6,6,5,3,3,2,2,7,0,1}; //数组中元素依次为: "sin","cos","tan","cot","arcsin","arccos","arctan","sec","csc","ln","^","*","/"," ","-","(",")","" 的栈外(因为有的运算符是从右向左计算,有的是从左往右计算,用内外优先级可以限制其执行顺序)优先级 //public int[]isp={5,5,5,5,5,5,5,5,5,5,5,4,3,3,2,2,1,1}; //数组中元素依次为: "sin","cos","tan","cot","arcsin","arccos","arctan","sec","csc","ln","^","*","/"," ","-","(","end" 的栈内(因为有的运算符是从右向左计算,有的是从左往右计算,用内外优先级可以限制其执行顺序)优先级 opchTbl[0].op= "sin" ; opchTbl[0].code=1; opchTbl[0].grade= 's' ; opchTbl[1].op= "cos" ; opchTbl[1].code=2; opchTbl[1].grade= 's' ; opchTbl[2].op= "tan" ; opchTbl[2].code=3; opchTbl[2].grade= 's' ; opchTbl[3].op= "cot" ; opchTbl[3].code=4; opchTbl[3].grade= 's' ; opchTbl[4].op= "arcsin" ; opchTbl[4].code=5; opchTbl[4].grade= 's' ; opchTbl[5].op= "arccos" ; opchTbl[5].code=6; opchTbl[5].grade= 's' ; opchTbl[6].op= "arctan" ; opchTbl[6].code=7; opchTbl[6].grade= 's' ; opchTbl[7].op= "arccot" ; opchTbl[7].code=8; opchTbl[7].grade= 's' ; opchTbl[8].op= "sec" ; opchTbl[8].code=9; opchTbl[8].grade= 's' ; opchTbl[9].op= "csc" ; opchTbl[9].code=10; opchTbl[9].grade= 's' ; opchTbl[10].op= "ln" ; opchTbl[10].code=11; opchTbl[10].grade= 's' ; opchTbl[11].op= "^" ; opchTbl[11].code=12; opchTbl[11].grade= 'd' ; opchTbl[12].op= "*" ; opchTbl[12].code=13; opchTbl[12].grade= 'd' ; opchTbl[13].op= "/" ; opchTbl[13].code=14; opchTbl[13].grade= 'd' ; opchTbl[14].op= " " ; opchTbl[14].code=15; opchTbl[14].grade= 'd' ; opchTbl[15].op= "-" ; opchTbl[15].code=16; opchTbl[15].grade= 'd' ; opchTbl[16].op= "(" ; opchTbl[16].code=17; opchTbl[16].grade= 'd' ; opchTbl[17].op= ")" ; opchTbl[17].code=18; opchTbl[17].grade= 'd' ; opchTbl[18].op= " " ; opchTbl[18].code=19; opchTbl[18].grade= 'd' ; startString=expressBox.Text; //将输入的运算表达式存入"起始字符串" //dataStack.Initialize(); operateStack.Initialize(); } public void CreterionFaction() { //以下为消去待扫描字符串中的所有空格字符 for ( int i=0;i<startString.Length;i ) if (startString[i].Equals( ' ' )) { startString=startString.Remove(i,1); i--; } //以下代码使待扫描字符串的单目(' '和'-')变为双目 if (startString.Length!=0) if (startString[0]== ' ' ||startString[0]== '-' ) { startString=startString.Insert(0, "0" ); } for ( int i=0;i<startString.Length-1;i ) { if ((startString[i]== '(' )&&(startString[i 1]== '-' )) startString=startString.Insert(i 1, "0" ); } startString=startString.Insert(startString.Length, ")" ); //将待扫描字符串字号字母转化为小写字母 startString=startString.ToLower(); ////**试验用语句 //label4.Text=startString; } public bool CheckParentthese() //检查括号是否匹配 { int number=0; for ( int i=0;i<startString.Length-1;i ) { if (i== '(' ) number ; if (i== ')' ) number--; if (number<0) return false ; } if (number!=0) { return false ; } return true ; } public int CheckFollowCorrect() //给运算表达式分块(三角函数...算术运算符等),再根据其返回值来检验其属于哪类错误 { string str,oldString= "" ,newString= "" ; int dataCount=0,characterCount=0; if (startString.Equals( ")" )) return 0; //输入字符串为空返回值 if ((startString[0]== '*' )||(startString[0]== '/' )||(startString[0]== '^' )||(startString[0]== ')' )) return 11; //首字符输入错误返回值 for ( int i=0;i<startString.Length;i ) { if ((oldString.Equals( "三角函数" ))&&(newString.Equals( "右括号" ))) return 2; //三角函数直接接右括号错误返回值 if ((oldString.Equals( "左括号" ))&&(newString.Equals( "算术运算符" ))) return 3; //左括号直接接算术运算符错误返回值 if ((oldString.Equals( "数字序列" ))&&(newString.Equals( "三角函数" ))) return 4; //数字序列后直接接三角函数错误返回值 if ((oldString.Equals( "数字序列" ))&&(newString.Equals( "左括号" ))) return 5; //数字序列后直接接左括号错误返回值 if ((oldString.Equals( "算术运算符" ))&&(newString.Equals( "右括号" ))) return 6; //算术运算符后直接接右括号错误返回值 if ((oldString.Equals( "右括号" ))&&(newString.Equals( "左括号" ))) return 7; //右括号直接接左括号错误返回值 if ((oldString.Equals( "右括号" ))&&(newString.Equals( "三角函数" ))) return 8; //右括号直接接三角函数错误返回值 if ((oldString.Equals( "数字序列" ))&&(newString.Equals( "数字序列" ))) return 9; //数字序列后直接接'pi'/'e'或'pi'/'e'直接接数字序列错误返回值 if ((oldString.Equals( "算术运算符" ))&&(newString.Equals( "算术运算符" ))) return 10; //算术运算符后直接接算术运算符错误返回值 oldString=newString; if (i<startString.Length-5&&startString.Length>=6) { str=startString.Substring(i,6); if ((str.CompareTo( "arcsin" )==0)||(str.CompareTo( "arccos" )==0)||(str.CompareTo( "arctan" )==0)||(str.CompareTo( "arccot" )==0)) { newString= "三角函数" ; i =5; characterCount ; continue ; } } if (i<startString.Length-2&&startString.Length>=3) { str=startString.Substring(i,3); if ((str.CompareTo( "sin" )==0)||(str.CompareTo( "cos" )==0)||(str.CompareTo( "tan" )==0)||(str.CompareTo( "cot" )==0)||(str.CompareTo( "sec" )==0)||(str.CompareTo( "csc" )==0)) { newString= "三角函数" ; i =2; characterCount ; continue ; } } if (i<(startString.Length-1)&&(startString.Length)>=2) { str=startString.Substring(i,2); if (str.CompareTo( "ln" )==0) { newString= "三角函数" ; i =1; characterCount ; continue ; } if (str.CompareTo( "pi" )==0) { newString= "数字序列" ; i =1;dataCount ; continue ; } } str=startString.Substring(i,1); if (str.Equals( "^" )||str.Equals( "*" )||str.Equals( "/" )||str.Equals( " " )||str.Equals( "-" )) { newString= "算术运算符" ; characterCount ; continue ; } if (str.Equals( "e" )) { newString= "数字序列" ; dataCount ; continue ; } /* if (str.Equals( "x" )) { newString= "数字序列" ; dataCount ; continue ; }*/ if (str.Equals( "(" )) { newString= "左括号" ; characterCount ; continue ; } if (str.Equals( ")" )) { newString= "右括号" ; characterCount ; continue ; } if (Char.IsDigit(startString[i])) { while (Char.IsDigit(startString[i])) { i ; } if (startString[i]== '.' &&(!Char.IsDigit(startString[i 1]))&&(i 1)!=startString.Length) return 13; if (startString[i]== '.' ) { i ; } while (Char.IsDigit(startString[i])) { i ; } newString= "数字序列" ; i--; dataCount ; continue ; } return 1; //非法字符 } if ((dataCount==0&&characterCount!=0)||(startString[0]== '0' &&dataCount==1&&characterCount>1&&startString.Length!=2)) return 12; return 100; } public int IsCharacterOrData( ref double num) { string str= "" ; startTop =startTopMoveCount; startTopMoveCount=0; int i=startTop; if (i<startString.Length-5&&startString.Length>=6) { str=startString.Substring(i,6); for ( int j=4;j<=7;j ) if (str.Equals(opchTbl[j].op)) { startTopMoveCount=6; return opchTbl[j].code; } } if (i<startString.Length-2&&startString.Length>=3) { str=startString.Substring(i,3); for ( int j=0;j<10;j ) if (str.CompareTo(opchTbl[j].op)==0) { startTopMoveCount=3; return opchTbl[j].code; } } if (i<(startString.Length-1)&&(startString.Length)>=2) { str=startString.Substring(i,2); if (str.CompareTo( "ln" )==0) { startTopMoveCount=2; return 11; } if (str.CompareTo( "pi" )==0) { startTopMoveCount=2; num=Math.PI; return 100; } } //以下开始确认一个字符是属于什么值类型 if (i<startString.Length) { str=startString.Substring(i,1); for ( int j=11;j<19;j ) { if (str.Equals(opchTbl[j].op)) {startTopMoveCount=1; return opchTbl[j].code;} } if (str.CompareTo( "e" )==0) { startTopMoveCount=1; num=Math.E; return 100; } /*if(str.CompareTo("x")==0) { startTopMoveCount=1; num=variableX; return 100; }*/ if (Char.IsDigit(startString[i])) { double temp=0,M=10; int j=i; while (Char.IsDigit(startString[j])) { temp=M*temp Char.GetNumericValue(startString[j]); startTop ; j ; } if (startString[j]== '.' ) { j ;startTop ; } while (Char.IsDigit(startString[j])) { temp =1.0/M*Char.GetNumericValue(startString[j]); M/=10;j ; startTop ; } startTopMoveCount=0; num=temp; return 100; } } return -1; } public double DoubleCount( string opString, double data1, double data2) { //双目运算 if (opString.CompareTo( " " )==0) return (data1 data2); if (opString.CompareTo( "-" )==0) return (data1-data2); if (opString.CompareTo( "*" )==0) return (data1*data2); if (opString.CompareTo( "/" )==0) return (data1/data2); if (opString.CompareTo( "^" )==0) { double end=data1; for ( int i=0;i<data2-1;i ) end*=data1; return (end); } return Double.MaxValue; //定义域不对,返回 } public double DoubleCount( string opString, double data1) { //单目运算 if (opString.CompareTo( "sin" )==0) return Math.Sin(data1); if (opString.CompareTo( "cos" )==0) return Math.Cos(data1); if (opString.CompareTo( "tan" )==0) return Math.Tan(data1); if (opString.CompareTo( "cot" )==0) return (1/(Math.Tan(data1))); if (opString.CompareTo( "arcsin" )==0) if (-1<=data1&&data1<=1) return Math.Asin(data1); if (opString.CompareTo( "arccos" )==0) if (-1<=data1&&data1<=1) return Math.Acos(data1); if (opString.CompareTo( "arctan" )==0) if (-Math.PI/2<=data1&&data1<=Math.PI/2) return Math.Atan(data1); if (opString.CompareTo( "arccot" )==0) if (-Math.PI/2<=data1&&data1<=Math.PI/2) return (-Math.Atan(data1)); if (opString.CompareTo( "sec" )==0) return (1/(Math.Cos(data1))); if (opString.CompareTo( "csc" )==0) return (1/(Math.Sin(data1))); if (data1>0) if (opString.CompareTo( "ln" )==0) return Math.Log(data1); return Double.MaxValue; //定义域不对 } public bool CountValueY( ref double tempY) //方法功能为求得解 { int type=-1; //存放正在扫描的字符串是为数字类型还是(单双目运算符) double num=0; //如果是数据,则返回数据的值 //进栈底结束符"end" opTop ; operateStack[opTop].op= "end" ; operateStack[opTop].code=18; operateStack[opTop].grade= ' ' ; while (startTop<=startString.Length-1) { start: type=IsCharacterOrData( ref num); //调用判断返回值类型函数 //if(type==17) ; if (type==-1){ return false ;} if (type==100) { dataTop=dataTop 1; //Console.WriteLine(dataTop); dataStack[dataTop]=num; } else { if (osp[type-1]>isp[operateStack[opTop].code-1]) //操作符进栈 { opTop ; operateStack[opTop].op=opchTbl[type-1].op; operateStack[opTop].code=opchTbl[type-1].code; operateStack[opTop].grade=opchTbl[type-1].grade; } else { while (osp[type-1]<=isp[operateStack[opTop].code-1]) //弹出操作符跟数据计算,并存入数据 { if (operateStack[opTop].op.CompareTo( "end" )==0) //当遇到"end"结束符表示已经获得结果 { if (dataTop==0) { tempY=dataStack[dataTop]; startTop=0; startTopMoveCount=0; opTop=-1; dataTop=-1; return true ; } else return false ; //运算符和数据的个数不匹配造成的错误 } if (operateStack[opTop].op.CompareTo( "(" )==0) //如果要弹出操作数为'( ',则消去左括号 { opTop--; goto start; } //弹出操作码和一个或两个数据计算,并将计算结果存入数据栈 double data1,data2; opTable operate; if (dataTop>=0) data2=dataStack[dataTop]; else return false ; operate.op=operateStack[opTop].op; operate.code=operateStack[opTop].code; operate.grade=operateStack[opTop].grade; opTop--; //处理一次,指针必须仅且只能下移一个单位 if (operate.grade== 'd' ) { if (dataTop-1>=0) data1=dataStack[dataTop-1]; else return false ; double tempValue=DoubleCount(operate.op,data1,data2); if (tempValue!=Double.MaxValue) dataStack[--dataTop]=tempValue; else return false ; } if (operate.grade== 's' ) { double tempValue=DoubleCount(operate.op,data2); if (tempValue!=Double.MaxValue) dataStack[dataTop]=tempValue; else return false ; } } //如果当前栈外操作符比栈顶的操作符优先级别高,则栈外操作符进栈 opTop ; operateStack[opTop].op=opchTbl[type-1].op; operateStack[opTop].code=opchTbl[type-1].code; operateStack[opTop].grade=opchTbl[type-1].grade; } } } return false ; } public void StartExcute() { InitializeOpchTblStack(); CreterionFaction(); if (CheckParentthese()== false ) { MessageBox.Show( "括号不匹配,请重新输入!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; } switch (CheckFollowCorrect()) { case 0: MessageBox.Show( "表达式为空,请先输入表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Warning); return ; case 1: MessageBox.Show( "表达式中有非法字符!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 2: MessageBox.Show( "三角函数运算符与 ) 之间应输入数据或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 3: MessageBox.Show( "' ( ' 与算术运算符之间应输入数据或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 4: MessageBox.Show( "数字数列与三角函数之间应输入算术运算符或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 5: MessageBox.Show( "数字数列与 ' ( ' 之间应输入算术运算符或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 6: MessageBox.Show( "算术运算符与右括号之间应输入数据或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 7: MessageBox.Show( "' ) ' 与 ' ( ' 之间应输入算术运算符或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 8: MessageBox.Show( "' ) ' 与三角函数之间应输入算术运算符或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 9: MessageBox.Show( "常量 ' PI ' 或 ' E ' 或 ' X ' 与数字数据之间应输入算术运算符或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 10: MessageBox.Show( "算术运算符与算术运算符之间应输入数据或其它表达式!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 11: MessageBox.Show( "表达式头部不能为' ', ' - ' , ' * ' , ' / ' , ' ^ ' ,' ) '!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 12: MessageBox.Show( "仅有运算符号没有数字数据或数据缺少而无法计算,请输入数字数据!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; case 13: MessageBox.Show( "小数点后面缺少小数部分,请输入小数部分!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; } double tempY=0; switch (CountValueY( ref tempY)) { case false :MessageBox.Show( "输入的表达式不正确或反三角函数定义域在其定义域范围之外!!!" , "错误" ,MessageBoxButtons.OK,MessageBoxIcon.Error); return ; } endbox.Text=tempY.ToString(); //依次存档计算结果 endList.Text = "(" ; endList.Text =number; endList.Text = "). " ; number ; endList.Text =endbox.Text; endList.Text = " " ; } private void label4_Click( object sender, System.EventArgs e) { } private void label2_Click( object sender, System.EventArgs e) { } private void button30_Click( object sender, System.EventArgs e) { StartExcute(); } private void button10_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button10.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button11_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart, "." ); expressBox.SelectionStart=expressBox.TextLength; } private void button27_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart, "^" ); expressBox.SelectionStart=expressBox.TextLength; } private void button1_Click_1( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button1.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button4_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button4.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button3_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button3.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button2_Click_1( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button2.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button14_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button14.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button15_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button15.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button5_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button5.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button6_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button6.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button9_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button9.Text); expressBox.SelectionStart=expressBox.TextLength; //expressBox.SelectionStart =button9.Text.Length; } private void button8_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button8.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button7_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button7.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button12_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button12.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button13_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button13.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button29_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button29.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button28_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button28.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button16_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button16.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button20_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button20.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button17_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button17.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button21_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button21.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button24_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button24.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button18_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button18.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button22_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button22.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button25_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button25.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button19_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button19.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button23_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button23.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button26_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,button26.Text); expressBox.SelectionStart=expressBox.TextLength; } private void button31_Click( object sender, System.EventArgs e) { if (expressBox.Text.Length>0) expressBox.Text=expressBox.Text.Remove(expressBox.Text.Length-1,1); } private void button32_Click( object sender, System.EventArgs e) { expressBox.Text= "" ; endbox.Text= "0.000000" ; } private void button33_Click( object sender, System.EventArgs e) { expressBox.SelectedText= null ; expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart, "PI" ); expressBox.SelectionStart=expressBox.TextLength; } private void button34_Click( object sender, System.EventArgs e) { endList.Text= "" ; number=1; } private void button35_Click( object sender, System.EventArgs e) { MessageBox.Show( "\n\n数学常用字符表示如下:\n Л: PI\n 常量E: e或E\n CE: 清零\n\n在输入角度时直接输入角度值:\n 例如 sin30 中的30表示度数,结果为1/2.\n\n请用鼠标直接点击或用键盘输入表达式.\n" , "Help" ,MessageBoxButtons.OK,MessageBoxIcon.Question); } private void button36_Click( object sender, System.EventArgs e) { double temp= double .Parse(endbox.Text); if (temp<= double .MaxValue) { temp=temp*Math.PI/180; // textBox1.Text=temp.ToString(); } } private void button37_Click( object sender, System.EventArgs e) { double temp= double .Parse(endbox.Text.ToString()); temp=temp*180/Math.PI; // textBox2.Text=temp.ToString(); } private void button38_Click( object sender, System.EventArgs e) { //expressBox.Text=textBox1.Text; // expressBox.SelectedText=null; // expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,textBox1.Text); // expressBox.SelectionStart=expressBox.TextLength; } private void button39_Click( object sender, System.EventArgs e) { //expressBox.Text=textBox2.Text; // expressBox.SelectedText=null; // expressBox.Text=expressBox.Text.Insert(expressBox.SelectionStart,textBox2.Text); // expressBox.SelectionStart=expressBox.TextLength; } private void button40_Click( object sender, System.EventArgs e) { expressBox.Text= "" ; } private void endList_TextChanged( object sender, System.EventArgs e) { } private void label3_Click( object sender, System.EventArgs e) { } } } |
好例子网口号:伸出你的我的手 — 分享!
相关软件
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)