image.png

    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.Threading.Tasks;
    9. using System.Windows.Forms;
    10. namespace _125_计算器
    11. {
    12. public partial class Form1 : Form
    13. {
    14. public Form1()
    15. {
    16. InitializeComponent();
    17. }
    18. private void btnNum0_Click(object sender, EventArgs e)
    19. {
    20. txtDisplay.AppendText(btnNum0.Text);
    21. }
    22. private void btnNum1_Click(object sender, EventArgs e)
    23. {
    24. txtDisplay.AppendText(btnNum1.Text);
    25. }
    26. private void btnNum2_Click(object sender, EventArgs e)
    27. {
    28. txtDisplay.AppendText(btnNum2.Text);
    29. }
    30. private void btnNum3_Click(object sender, EventArgs e)
    31. {
    32. txtDisplay.AppendText(btnNum3.Text);
    33. }
    34. private void btnNum4_Click(object sender, EventArgs e)
    35. {
    36. txtDisplay.AppendText(btnNum4.Text);
    37. }
    38. private void btnNum5_Click(object sender, EventArgs e)
    39. {
    40. txtDisplay.AppendText(btnNum5.Text);
    41. }
    42. private void btnNum6_Click(object sender, EventArgs e)
    43. {
    44. txtDisplay.AppendText(btnNum6.Text);
    45. }
    46. private void btnNum7_Click(object sender, EventArgs e)
    47. {
    48. txtDisplay.AppendText(btnNum7.Text);
    49. }
    50. private void btnNum8_Click(object sender, EventArgs e)
    51. {
    52. txtDisplay.AppendText(btnNum8.Text);
    53. }
    54. private void btnNum9_Click(object sender, EventArgs e)
    55. {
    56. txtDisplay.AppendText(btnNum9.Text);
    57. }
    58. char Symbol;
    59. private void btnAdd_Click(object sender, EventArgs e)
    60. {
    61. txtDisplay.AppendText(btnAdd.Text);
    62. Symbol = '+';
    63. }
    64. private void btnMinus_Click(object sender, EventArgs e)
    65. {
    66. txtDisplay.AppendText(btnMinus.Text);
    67. Symbol = '-';
    68. }
    69. private void btnMultiply_Click(object sender, EventArgs e)
    70. {
    71. txtDisplay.AppendText(btnMultiply.Text);
    72. Symbol = '*';
    73. }
    74. private void btnDivide_Click(object sender, EventArgs e)
    75. {
    76. txtDisplay.AppendText(btnDivide.Text);
    77. Symbol = '/';
    78. }
    79. private void btnEqual_Click(object sender, EventArgs e)
    80. {
    81. double result;
    82. string input = txtDisplay.Text;
    83. if (Symbol == '+')
    84. {
    85. string[] nums = txtDisplay.Text.Split('+');
    86. result = Convert.ToDouble(nums[0]) + Convert.ToDouble(nums[1]);
    87. }
    88. else if (Symbol == '-')
    89. {
    90. string[] nums = txtDisplay.Text.Split('-');
    91. result = Convert.ToDouble(nums[0]) - Convert.ToDouble(nums[1]);
    92. }
    93. else if (Symbol == '*')
    94. {
    95. string[] nums = txtDisplay.Text.Split('*');
    96. result = Convert.ToDouble(nums[0]) * Convert.ToDouble(nums[1]);
    97. }
    98. else if (Symbol == '/')
    99. {
    100. string[] nums = txtDisplay.Text.Split('/');
    101. result = Convert.ToDouble(nums[0]) / Convert.ToDouble(nums[1]);
    102. }
    103. else
    104. {
    105. result = 999999999;
    106. }
    107. txtDisplay.Clear();
    108. txtDisplay.Text = result.ToString();
    109. }
    110. private void btnC_Click(object sender, EventArgs e)
    111. {
    112. txtDisplay.Clear();
    113. }
    114. private void btnBack_Click(object sender, EventArgs e)
    115. {
    116. try
    117. {
    118. txtDisplay.Text = txtDisplay.Text.Substring(0, txtDisplay.Text.Length - 1);
    119. }
    120. catch
    121. { }
    122. }
    123. private void Form1_Load(object sender, EventArgs e)
    124. {
    125. // txtDisplay.Text = "0";
    126. }
    127. }
    128. }