Form1.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 KotenkovCalk2
  11. {
  12. public partial class Calc : Form
  13. {
  14. public Calc()
  15. {
  16. InitializeComponent();
  17. }
  18. float a, b;
  19. int count;
  20. bool znak = true;
  21. private void ZeroBt_Click(object sender, EventArgs e)
  22. {
  23. textBox1.Text = textBox1.Text + 0;
  24. }
  25. private void OneBt_Click(object sender, EventArgs e)
  26. {
  27. textBox1.Text = textBox1.Text + 1;
  28. }
  29. private void TwoBt_Click(object sender, EventArgs e)
  30. {
  31. textBox1.Text = textBox1.Text + 2;
  32. }
  33. private void ThreeBt_Click(object sender, EventArgs e)
  34. {
  35. textBox1.Text = textBox1.Text + 3;
  36. }
  37. private void FourBt_Click(object sender, EventArgs e)
  38. {
  39. textBox1.Text = textBox1.Text + 4;
  40. }
  41. private void FiveBt_Click(object sender, EventArgs e)
  42. {
  43. textBox1.Text = textBox1.Text + 5;
  44. }
  45. private void SixBt_Click(object sender, EventArgs e)
  46. {
  47. textBox1.Text = textBox1.Text + 6;
  48. }
  49. private void SevenBt_Click(object sender, EventArgs e)
  50. {
  51. textBox1.Text = textBox1.Text + 7;
  52. }
  53. private void EigthBt_Click(object sender, EventArgs e)
  54. {
  55. textBox1.Text = textBox1.Text + 8;
  56. }
  57. private void NineBt_Click(object sender, EventArgs e)
  58. {
  59. textBox1.Text = textBox1.Text + 9;
  60. }
  61. private void button4_Click(object sender, EventArgs e)
  62. {
  63. a = float.Parse(textBox1.Text);
  64. textBox1.Clear();
  65. count = 1;
  66. label1.Text = a.ToString() + "+";
  67. znak = true;
  68. }
  69. private void button5_Click(object sender, EventArgs e)
  70. {
  71. a = float.Parse(textBox1.Text);
  72. textBox1.Clear();
  73. count = 2;
  74. label1.Text = a.ToString() + "-";
  75. znak = true;
  76. }
  77. private void button9_Click(object sender, EventArgs e)
  78. {
  79. a = float.Parse(textBox1.Text);
  80. textBox1.Clear();
  81. count = 3;
  82. label1.Text = a.ToString() + "*";
  83. znak = true;
  84. }
  85. private void button13_Click(object sender, EventArgs e)
  86. {
  87. a = float.Parse(textBox1.Text);
  88. textBox1.Clear();
  89. count = 4;
  90. label1.Text = a.ToString() + "/";
  91. znak = true;
  92. }
  93. private void GetResultBt_Click(object sender, EventArgs e)
  94. {
  95. calculate();
  96. label1.Text = "";
  97. }
  98. private void button19_Click(object sender, EventArgs e)
  99. {
  100. textBox1.Text = textBox1.Text + ",";
  101. }
  102. private void ClearBt_Click(object sender, EventArgs e)
  103. {
  104. textBox1.Text = "";
  105. label1.Text = "";
  106. }
  107. private void button2_Click(object sender, EventArgs e)
  108. {
  109. int lenght = textBox1.Text.Length - 1;
  110. string text = textBox1.Text;
  111. textBox1.Clear();
  112. for (int i = 0; i < lenght; i++)
  113. {
  114. textBox1.Text = textBox1.Text + text[i];
  115. }
  116. }
  117. private void button3_Click(object sender, EventArgs e)
  118. {
  119. if (znak == true)
  120. {
  121. textBox1.Text = "-" + textBox1.Text;
  122. znak = false;
  123. }
  124. else if (znak == false)
  125. {
  126. textBox1.Text = textBox1.Text.Replace("-", "");
  127. znak = true;
  128. }
  129. }
  130. private void calculate()
  131. {
  132. switch (count)
  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. b = a / float.Parse(textBox1.Text);
  148. textBox1.Text = b.ToString();
  149. break;
  150. default:
  151. break;
  152. }
  153. }
  154. }
  155. }