Form1.cs 5.2 KB

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