Form1.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Calculator
  11. {
  12. public partial class Form1 : Form
  13. {
  14. Double Result = 0;
  15. String OperDef = " ";
  16. bool IsOperator = false;
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21. private void button15_Click(object sender, EventArgs e)
  22. {
  23. if (textBox_Result.Text == "0" || IsOperator)
  24. textBox_Result.Clear();
  25. IsOperator = false;
  26. Button button = (Button)sender;
  27. if(button.Text == ".")
  28. {
  29. if(!textBox_Result.Text.Contains("."))
  30. textBox_Result.Text += button.Text;
  31. }
  32. else
  33. textBox_Result.Text += button.Text;
  34. }
  35. private void Operator_click_Event(object sender, EventArgs e)
  36. {
  37. Button button = (Button)sender;
  38. if (Result != 0)
  39. {
  40. button16.PerformClick();
  41. OperDef = button.Text;
  42. label_Show_Op.Text = Result + " " + OperDef;
  43. IsOperator = true;
  44. }
  45. else
  46. {
  47. OperDef = button.Text;
  48. Result = Double.Parse(textBox_Result.Text);
  49. label_Show_Op.Text = Result + " " + OperDef;
  50. IsOperator = true;
  51. }
  52. }
  53. private void button5_Click(object sender, EventArgs e)
  54. {
  55. textBox_Result.Text = "0";
  56. }
  57. private void button6_Click(object sender, EventArgs e)
  58. {
  59. label_Show_Op.Text = null;
  60. textBox_Result.Text = null;
  61. Result = 0;
  62. }
  63. private void button16_Click(object sender, EventArgs e)
  64. {
  65. switch (OperDef)
  66. {
  67. case "+":
  68. textBox_Result.Text = (Result + Double.Parse(textBox_Result.Text)).ToString();
  69. break;
  70. case "-":
  71. textBox_Result.Text = (Result - Double.Parse(textBox_Result.Text)).ToString();
  72. break;
  73. case "x":
  74. textBox_Result.Text = (Result * Double.Parse(textBox_Result.Text)).ToString();
  75. break;
  76. case "÷":
  77. textBox_Result.Text = (Result / Double.Parse(textBox_Result.Text)).ToString();
  78. break;
  79. default:
  80. break;
  81. }
  82. Result = Double.Parse(textBox_Result.Text);
  83. label_Show_Op.Text = null;
  84. }
  85. }
  86. }