Form1.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 Zharushkin_calculator2
  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 listBox1_SelectedIndexChanged(object sender, EventArgs e)
  51. {
  52. }
  53. private void button5_Click(object sender, EventArgs e)
  54. {
  55. a = float.Parse(textBox1.Text);
  56. textBox1.Clear();
  57. oper = 2;
  58. label1.Text = a.ToString() + "-";
  59. znak = true;
  60. }
  61. private void button6_Click(object sender, EventArgs e)
  62. {
  63. a = float.Parse(textBox1.Text);
  64. textBox1.Clear();
  65. oper = 3;
  66. label1.Text = a.ToString() + "*";
  67. znak = true;
  68. }
  69. private void button7_Click(object sender, EventArgs e)
  70. {
  71. a = float.Parse(textBox1.Text);
  72. textBox1.Clear();
  73. oper = 4;
  74. label1.Text = a.ToString() + "/";
  75. znak = true;
  76. }
  77. private void button3_Click(object sender, EventArgs e)
  78. {
  79. if (znak == true)
  80. {
  81. textBox1.Text = "-" + textBox1.Text;
  82. znak = false;
  83. }
  84. else if (znak == false)
  85. {
  86. textBox1.Text = textBox1.Text.Replace("-", "");
  87. znak = true;
  88. }
  89. }
  90. private void button10_Click(object sender, EventArgs e)
  91. {
  92. textBox1.Text = textBox1.Text + 0;
  93. }
  94. private void button11_Click(object sender, EventArgs e)
  95. {
  96. textBox1.Text = textBox1.Text + 1;
  97. }
  98. private void button12_Click(object sender, EventArgs e)
  99. {
  100. textBox1.Text = textBox1.Text + 2;
  101. }
  102. private void button13_Click(object sender, EventArgs e)
  103. {
  104. textBox1.Text = textBox1.Text + 3;
  105. }
  106. private void button16_Click(object sender, EventArgs e)
  107. {
  108. textBox1.Text = textBox1.Text + 4;
  109. }
  110. private void button15_Click(object sender, EventArgs e)
  111. {
  112. textBox1.Text = textBox1.Text + 5;
  113. }
  114. private void button14_Click(object sender, EventArgs e)
  115. {
  116. textBox1.Text = textBox1.Text + 7;
  117. }
  118. private void button19_Click(object sender, EventArgs e)
  119. {
  120. a = float.Parse(textBox1.Text);
  121. textBox1.Clear();
  122. oper = 7;
  123. label1.Text = a.ToString() + "+";
  124. znak = true;
  125. }
  126. private void button18_Click(object sender, EventArgs e)
  127. {
  128. textBox1.Text = textBox1.Text + 8;
  129. }
  130. private void button8_Click(object sender, EventArgs e)
  131. {
  132. calculate();
  133. label1.Text = "";
  134. }
  135. private void button1_Click(object sender, EventArgs e)
  136. {
  137. textBox1.Text = "";
  138. label1.Text = "";
  139. }
  140. private void button2_Click(object sender, EventArgs e)
  141. {
  142. int lenght = textBox1.Text.Length - 1;
  143. string text = textBox1.Text;
  144. textBox1.Clear();
  145. for (int i = 0; i < lenght; i++)
  146. {
  147. textBox1.Text = textBox1.Text + text[i];
  148. }
  149. }
  150. private void textBox1_TextChanged(object sender, EventArgs e)
  151. {
  152. }
  153. private void label1_Click(object sender, EventArgs e)
  154. {
  155. }
  156. private void button4_Click(object sender, EventArgs e)
  157. {
  158. a = float.Parse(textBox1.Text);
  159. textBox1.Clear();
  160. oper = 1;
  161. label1.Text = a.ToString() + "+";
  162. znak = true;
  163. }
  164. private void button17_Click(object sender, EventArgs e)
  165. {
  166. textBox1.Text = textBox1.Text + 9;
  167. }
  168. }
  169. }