Form1.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. namespace TuraevMiroshnichenkoCalc2
  10. {
  11. public partial class Calculator : Form
  12. {
  13. public Calculator()
  14. {
  15. InitializeComponent();
  16. }
  17. float a, b;
  18. int count;
  19. bool znak = true;
  20. private void button17_Click(object sender, EventArgs e)
  21. {
  22. textBox4.Text = textBox4.Text + 0;
  23. }
  24. private void button13_Click(object sender, EventArgs e)
  25. {
  26. textBox4.Text = textBox4.Text + 1;
  27. }
  28. private void button14_Click(object sender, EventArgs e)
  29. {
  30. textBox4.Text = textBox4.Text + 2;
  31. }
  32. private void button15_Click(object sender, EventArgs e)
  33. {
  34. textBox4.Text = textBox4.Text + 3;
  35. }
  36. private void button9_Click(object sender, EventArgs e)
  37. {
  38. textBox4.Text = textBox4.Text + 4;
  39. }
  40. private void button10_Click(object sender, EventArgs e)
  41. {
  42. textBox4.Text = textBox4.Text + 5;
  43. }
  44. private void button11_Click(object sender, EventArgs e)
  45. {
  46. textBox4.Text = textBox4.Text + 6;
  47. }
  48. private void button5_Click(object sender, EventArgs e)
  49. {
  50. textBox4.Text = textBox4.Text + 7;
  51. }
  52. private void button6_Click(object sender, EventArgs e)
  53. {
  54. textBox4.Text = textBox4.Text + 8;
  55. }
  56. private void button7_Click(object sender, EventArgs e)
  57. {
  58. textBox4.Text = textBox4.Text + 9;
  59. }
  60. private void button4_Click(object sender, EventArgs e)
  61. {
  62. a = float.Parse(textBox4.Text);
  63. textBox4.Clear();
  64. count = 1;
  65. label1.Text = a.ToString() + "+";
  66. znak = true;
  67. }
  68. private void button8_Click(object sender, EventArgs e)
  69. {
  70. a = float.Parse(textBox4.Text);
  71. textBox4.Clear();
  72. count = 2;
  73. label1.Text = a.ToString() + "-";
  74. znak = true;
  75. }
  76. private void button12_Click(object sender, EventArgs e)
  77. {
  78. a = float.Parse(textBox4.Text);
  79. textBox4.Clear();
  80. count = 3;
  81. label1.Text = a.ToString() + "*";
  82. znak = true;
  83. }
  84. private void button16_Click(object sender, EventArgs e)
  85. {
  86. a = float.Parse(textBox4.Text);
  87. textBox4.Clear();
  88. count = 4;
  89. label1.Text = a.ToString() + "/";
  90. znak = true;
  91. }
  92. private void button19_Click(object sender, EventArgs e)
  93. {
  94. calculate();
  95. label1.Text = "";
  96. }
  97. private void button18_Click(object sender, EventArgs e)
  98. {
  99. textBox4.Text = textBox4.Text + ",";
  100. }
  101. private void button1_Click(object sender, EventArgs e)
  102. {
  103. textBox4.Text = "";
  104. label1.Text = "";
  105. }
  106. private void button2_Click(object sender, EventArgs e)
  107. {
  108. int lenght = textBox4.Text.Length - 1;
  109. string text = textBox4.Text;
  110. textBox4.Clear();
  111. for (int i = 0; i < lenght; i++)
  112. {
  113. textBox4.Text = textBox4.Text + text[i];
  114. }
  115. }
  116. private void button3_Click(object sender, EventArgs e)
  117. {
  118. if (znak == true)
  119. {
  120. textBox4.Text = "-" + textBox4.Text;
  121. znak = false;
  122. }
  123. else if (znak == false)
  124. {
  125. textBox4.Text = textBox4.Text.Replace("-", "");
  126. znak = true;
  127. }
  128. }
  129. private void calculate()
  130. {
  131. switch (count)
  132. {
  133. case 1:
  134. b = a + float.Parse(textBox4.Text);
  135. textBox4.Text = b.ToString();
  136. break;
  137. case 2:
  138. b = a - float.Parse(textBox4.Text);
  139. textBox4.Text = b.ToString();
  140. break;
  141. case 3:
  142. b = a * float.Parse(textBox4.Text);
  143. textBox4.Text = b.ToString();
  144. break;
  145. case 4:
  146. b = a / float.Parse(textBox4.Text);
  147. textBox4.Text = b.ToString();
  148. break;
  149. default:
  150. break;
  151. }
  152. }
  153. }
  154. }