Form1.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 Chekryshov_Calculator
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void Form1_Load(object sender, EventArgs e)
  19. {
  20. }
  21. float a, b;
  22. int oper;
  23. bool znak = true;
  24. private void button5_Click(object sender, EventArgs e)
  25. {
  26. textBox1.Text = textBox1.Text + 7;
  27. }
  28. private void button6_Click(object sender, EventArgs e)
  29. {
  30. textBox1.Text = textBox1.Text + 8;
  31. }
  32. private void button7_Click(object sender, EventArgs e)
  33. {
  34. textBox1.Text = textBox1.Text + 9;
  35. }
  36. private void button11_Click(object sender, EventArgs e)
  37. {
  38. textBox1.Text = textBox1.Text + 6;
  39. }
  40. private void button10_Click(object sender, EventArgs e)
  41. {
  42. textBox1.Text = textBox1.Text + 5;
  43. }
  44. private void button9_Click(object sender, EventArgs e)
  45. {
  46. textBox1.Text = textBox1.Text + 4;
  47. }
  48. private void button15_Click(object sender, EventArgs e)
  49. {
  50. textBox1.Text = textBox1.Text + 3;
  51. }
  52. private void button14_Click(object sender, EventArgs e)
  53. {
  54. textBox1.Text = textBox1.Text + 2;
  55. }
  56. private void button13_Click(object sender, EventArgs e)
  57. {
  58. textBox1.Text = textBox1.Text + 1;
  59. }
  60. private void button17_Click(object sender, EventArgs e)
  61. {
  62. textBox1.Text = textBox1.Text + 0;
  63. }
  64. private void button4_Click(object sender, EventArgs e)
  65. {
  66. a = float.Parse(textBox1.Text);
  67. textBox1.Clear();
  68. oper = 1;
  69. label1.Text = a.ToString() + "+";
  70. znak = true;
  71. }
  72. private void button8_Click(object sender, EventArgs e)
  73. {
  74. a = float.Parse(textBox1.Text);
  75. textBox1.Clear();
  76. oper = 1;
  77. label1.Text = a.ToString() + "-";
  78. znak = true;
  79. }
  80. private void button12_Click(object sender, EventArgs e)
  81. {
  82. a = float.Parse(textBox1.Text);
  83. textBox1.Clear();
  84. oper = 1;
  85. label1.Text = a.ToString() + "*";
  86. znak = true;
  87. }
  88. private void button16_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 button18_Click(object sender, EventArgs e)
  97. {
  98. textBox1.Text = textBox1.Text + ",";
  99. }
  100. private void button19_Click(object sender, EventArgs e)
  101. {
  102. switch (oper)
  103. {
  104. case 1:
  105. b = a + float.Parse(textBox1.Text);
  106. textBox1.Text = b.ToString();
  107. break;
  108. case 2:
  109. b = a - float.Parse(textBox1.Text);
  110. textBox1.Text = b.ToString();
  111. break;
  112. case 3:
  113. b = a * float.Parse(textBox1.Text);
  114. textBox1.Text = b.ToString();
  115. break;
  116. case 4:
  117. if (float.Parse(textBox1.Text) == 0)
  118. { textBox1.Text = "Делить на 0 нельзя!"; }
  119. else
  120. {
  121. b = a / float.Parse(textBox1.Text);
  122. textBox1.Text = b.ToString();
  123. }
  124. break;
  125. default:
  126. break;
  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 button1_Click(object sender, EventArgs e)
  140. {
  141. textBox1.Text = "";
  142. label1.Text = "";
  143. }
  144. private void button3_Click(object sender, EventArgs e)
  145. {
  146. if (znak == true)
  147. {
  148. textBox1.Text = "-" + textBox1.Text;
  149. znak = false;
  150. }
  151. else if (znak == false)
  152. {
  153. textBox1.Text = textBox1.Text.Replace("-", "");
  154. znak = true;
  155. }
  156. }
  157. }
  158. }