Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  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.  
  11. namespace Projekt_1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. string A = "";
  21. string B = "";
  22. int Aint;
  23. int Bint;
  24. string OPER;
  25. int licz = 0;
  26.  
  27.  
  28.  
  29. private void button1_Click(object sender, EventArgs e)
  30. {
  31. if (licz == 0)
  32. {
  33. A += "1";
  34. textBox1.Text += "1";
  35. }
  36. else
  37. {
  38. B += "1";
  39. textBox1.Text += "1";
  40. }
  41. }
  42.  
  43. private void button2_Click(object sender, EventArgs e)
  44. {
  45. if (licz == 0)
  46. {
  47. A += "2";
  48. textBox1.Text += "2";
  49. }
  50. else
  51. {
  52. B += "2";
  53. textBox1.Text += "2";
  54. }
  55. }
  56.  
  57. private void button3_Click(object sender, EventArgs e)
  58. {
  59. if (licz == 0)
  60. {
  61. A += "3";
  62. textBox1.Text += "3";
  63. }
  64. else
  65. {
  66. B += "3";
  67. textBox1.Text += "3";
  68. }
  69. }
  70.  
  71. private void button4_Click(object sender, EventArgs e)
  72. {
  73. if (licz == 0)
  74. {
  75. A += "4";
  76. textBox1.Text += "4";
  77. }
  78. else
  79. {
  80. B += "4";
  81. textBox1.Text += "4";
  82. }
  83. }
  84.  
  85. private void button5_Click(object sender, EventArgs e)
  86. {
  87. if (licz == 0)
  88. {
  89. A += "5";
  90. textBox1.Text += "5";
  91. }
  92. else
  93. {
  94. B += "5";
  95. textBox1.Text += "5";
  96. }
  97. }
  98.  
  99. private void button6_Click(object sender, EventArgs e)
  100. {
  101. if (licz == 0)
  102. {
  103. A += "6";
  104. textBox1.Text += "6";
  105. }
  106. else
  107. {
  108. B += "6";
  109. textBox1.Text += "6";
  110. }
  111. }
  112.  
  113. private void button7_Click(object sender, EventArgs e)
  114. {
  115. if (licz == 0)
  116. {
  117. A += "7";
  118. textBox1.Text += "7";
  119. }
  120. else
  121. {
  122. B += "7";
  123. textBox1.Text += "7";
  124. }
  125. }
  126.  
  127. private void button8_Click(object sender, EventArgs e)
  128. {
  129. if (licz == 0)
  130. {
  131. A += "8";
  132. textBox1.Text += "8";
  133. }
  134. else
  135. {
  136. B += "8";
  137. textBox1.Text += "8";
  138. }
  139. }
  140.  
  141. private void button9_Click(object sender, EventArgs e)
  142. {
  143. if (licz == 0)
  144. {
  145. A += "9";
  146. textBox1.Text += "9";
  147. }
  148. else
  149. {
  150. B += "9";
  151. textBox1.Text += "9";
  152. }
  153. }
  154.  
  155. private void button10_Click(object sender, EventArgs e)
  156. {
  157. if (licz == 0)
  158. {
  159. A += "0";
  160. textBox1.Text += "0";
  161. }
  162. else
  163. {
  164. B += "0";
  165. textBox1.Text += "0";
  166. }
  167. }
  168.  
  169. private void button15_Click(object sender, EventArgs e)
  170. {
  171. Int32.TryParse(A, out Aint);
  172. Int32.TryParse(B, out Bint);
  173.  
  174. if ( !String.IsNullOrEmpty(A) && !String.IsNullOrEmpty(B) && OPER != null)
  175.  
  176.  
  177.  
  178. switch (OPER)
  179. {
  180. case "+":
  181. textBox1.Text += "=" + (Aint + Bint).ToString();
  182. break;
  183.  
  184. case "-":
  185. textBox1.Text += "=" + (Aint - Bint).ToString();
  186. break;
  187.  
  188. case "*":
  189. textBox1.Text += "=" + (Aint * Bint).ToString();
  190. break;
  191.  
  192. case "^":
  193. textBox1.Text += "=" + Math.Pow(Aint,Bint).ToString();
  194. break;
  195.  
  196. case "/":
  197. try
  198. {
  199. textBox1.Text += "=" + (Aint / Bint).ToString();
  200. }
  201. catch (Exception err)
  202. {
  203. MessageBox.Show("Nie dzielimy przez zero!", "Uwaga", MessageBoxButtons.OK);
  204. }
  205. finally
  206. {
  207. }
  208. break;
  209.  
  210.  
  211. }
  212. A = "";
  213. B = "";
  214. OPER = null;
  215. licz = 0;
  216. }
  217.  
  218. private void button11_Click(object sender, EventArgs e)
  219. {
  220. if (OPER == null && !String.IsNullOrEmpty(A))
  221. {
  222. OPER += "+";
  223. textBox1.Text += "+";
  224. licz = 1;
  225. }
  226. }
  227.  
  228. private void button12_Click(object sender, EventArgs e)
  229. {
  230. if (OPER == null && !String.IsNullOrEmpty(A))
  231. {
  232. OPER += "-";
  233. textBox1.Text += "-";
  234. licz = 1;
  235. }
  236. }
  237.  
  238. private void button13_Click(object sender, EventArgs e)
  239. {
  240. if (OPER == null && !String.IsNullOrEmpty(A))
  241. {
  242. OPER += "*";
  243. textBox1.Text += "*";
  244. licz = 1;
  245. }
  246. }
  247.  
  248. private void button14_Click(object sender, EventArgs e)
  249. {
  250. if (OPER == null && !String.IsNullOrEmpty(A))
  251. {
  252. OPER += "/";
  253. textBox1.Text += "/";
  254. licz = 1;
  255. }
  256. }
  257.  
  258. private void button16_Click(object sender, EventArgs e)
  259. {
  260. if (OPER == null && !String.IsNullOrEmpty(A))
  261. {
  262. OPER += "^";
  263. textBox1.Text += "^";
  264. licz = 1;
  265. }
  266. }
  267.  
  268. private void button17_Click(object sender, EventArgs e)
  269. {
  270. textBox1.Clear();
  271. A = "";
  272. B = "";
  273. OPER = null;
  274. licz = 0;
  275. Aint = 0;
  276. Bint = 0;
  277.  
  278. }
  279.  
  280. //private void check()
  281. //{
  282. // string slowo = "a+b=c";
  283.  
  284. // string[] val = slowo.split("+".tochararray());
  285. // a = int32.parse(val[0]);
  286. // b = int32.parse(val[1].split("=".tochararray())[0]);
  287. //}
  288.  
  289.  
  290. }
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement