Form1.cs 5.0 KB

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