Form1.cs 5.0 KB

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