Form1.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 OdintsovCalc2
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. float a, b;
  19. int count;
  20. bool znak = true;
  21. private void button17_Click(object sender, EventArgs e)
  22. {
  23. textBox1.Text = textBox1.Text + 0;
  24. }
  25. private void button13_Click(object sender, EventArgs e)
  26. {
  27. textBox1.Text = textBox1.Text + 1;
  28. }
  29. private void button14_Click(object sender, EventArgs e)
  30. {
  31. textBox1.Text = textBox1.Text + 2;
  32. }
  33. private void button15_Click(object sender, EventArgs e)
  34. {
  35. textBox1.Text = textBox1.Text + 3;
  36. }
  37. private void button9_Click(object sender, EventArgs e)
  38. {
  39. textBox1.Text = textBox1.Text + 4;
  40. }
  41. private void button10_Click(object sender, EventArgs e)
  42. {
  43. textBox1.Text = textBox1.Text + 5;
  44. }
  45. private void button11_Click(object sender, EventArgs e)
  46. {
  47. textBox1.Text = textBox1.Text + 6;
  48. }
  49. private void button5_Click(object sender, EventArgs e)
  50. {
  51. textBox1.Text = textBox1.Text + 7;
  52. }
  53. private void button6_Click(object sender, EventArgs e)
  54. {
  55. textBox1.Text = textBox1.Text + 8;
  56. }
  57. private void button7_Click(object sender, EventArgs e)
  58. {
  59. textBox1.Text = textBox1.Text + 9;
  60. }
  61. private void button18_Click(object sender, EventArgs e)
  62. {
  63. textBox1.Text = textBox1.Text + ",";
  64. }
  65. private void button4_Click(object sender, EventArgs e)
  66. {
  67. try
  68. {
  69. a = float.Parse(textBox1.Text);
  70. textBox1.Clear();
  71. count = 1;
  72. label2.Text = a.ToString() + "+";
  73. znak = true;
  74. }
  75. catch
  76. {
  77. textBox1.Text = "Не верный ввод";
  78. };
  79. }
  80. private void button8_Click(object sender, EventArgs e)
  81. {
  82. try
  83. {
  84. a = float.Parse(textBox1.Text);
  85. textBox1.Clear();
  86. count = 2;
  87. label2.Text = a.ToString() + "-";
  88. znak = true;
  89. }
  90. catch
  91. {
  92. textBox1.Text = "Не верный ввод";
  93. };
  94. }
  95. private void button12_Click(object sender, EventArgs e)
  96. {
  97. try
  98. {
  99. a = float.Parse(textBox1.Text);
  100. textBox1.Clear();
  101. count = 3;
  102. label2.Text = a.ToString() + "*";
  103. znak = true;
  104. }
  105. catch
  106. {
  107. textBox1.Text = "Не верный ввод";
  108. };
  109. }
  110. private void button16_Click(object sender, EventArgs e)
  111. {
  112. try
  113. {
  114. a = float.Parse(textBox1.Text);
  115. textBox1.Clear();
  116. count = 4;
  117. label2.Text = a.ToString() + "/";
  118. znak = true;
  119. }
  120. catch
  121. {
  122. textBox1.Text = "Не верный ввод";
  123. };
  124. }
  125. private void button19_Click(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. calculate();
  130. label2.Text = "";
  131. }
  132. catch
  133. {
  134. textBox1.Text = "Не верный ввод";
  135. };
  136. }
  137. private void calculate()
  138. {
  139. try
  140. {
  141. switch (count)
  142. {
  143. case 1:
  144. b = a + float.Parse(textBox1.Text);
  145. textBox1.Text = b.ToString();
  146. break;
  147. case 2:
  148. b = a - float.Parse(textBox1.Text);
  149. textBox1.Text = b.ToString();
  150. break;
  151. case 3:
  152. b = a * float.Parse(textBox1.Text);
  153. textBox1.Text = b.ToString();
  154. break;
  155. case 4:
  156. b = a / float.Parse(textBox1.Text);
  157. textBox1.Text = b.ToString();
  158. break;
  159. default:
  160. break;
  161. };
  162. }
  163. catch
  164. {
  165. textBox1.Text = "Не верный ввод";
  166. };
  167. }
  168. private void button3_Click(object sender, EventArgs e)
  169. {
  170. try
  171. {
  172. textBox1.Text = "";
  173. label2.Text = "";
  174. }
  175. catch
  176. {
  177. textBox1.Text = "Не верный ввод";
  178. };
  179. }
  180. private void button2_Click(object sender, EventArgs e)
  181. {
  182. try
  183. {
  184. int lenght = textBox1.Text.Length - 1;
  185. string text = textBox1.Text;
  186. textBox1.Clear();
  187. for (int i = 0; i < lenght; i++)
  188. {
  189. textBox1.Text = textBox1.Text + text[i];
  190. }
  191. }
  192. catch
  193. {
  194. textBox1.Text = "Не верный ввод";
  195. };
  196. }
  197. private void button1_Click(object sender, EventArgs e)
  198. {
  199. try
  200. {
  201. if (znak == true)
  202. {
  203. textBox1.Text = "-" + textBox1.Text;
  204. znak = false;
  205. }
  206. else if (znak == false)
  207. {
  208. textBox1.Text = textBox1.Text.Replace("-", "");
  209. znak = true;
  210. }
  211. }
  212. catch
  213. {
  214. textBox1.Text = "Не верный ввод";
  215. };
  216. }
  217. }
  218. }