Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.41 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 WindowsFormsApp1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. double f, s;
  16. double sum;
  17. bool root = false;
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. private void textBox1_TextChanged(object sender, EventArgs e)
  24. {
  25.  
  26. }
  27. public string Calc(string n)
  28. {
  29.  
  30. if (n.Contains("-") || n.Contains("+") || n.Contains("*") || n.Contains("/") || n.Contains("^") || n.Contains("√") || n.Contains("("))
  31. {
  32. if (n.Contains("("))
  33. {
  34. return n = Calc((n.Substring(0,n.IndexOf('(')))+Calc(n.Substring(n.IndexOf('(') + 1, (n.IndexOf(')') - n.IndexOf('(') - 1)))+n.Substring(n.IndexOf(')') + 1));
  35. }
  36. if (n.Contains("-"))
  37. {
  38. return (double.Parse(Calc(n.Substring(0, n.IndexOf('-')))) - double.Parse(Calc(n.Substring(n.IndexOf('-') + 1)))).ToString();
  39. }
  40. else if (n.Contains("+"))
  41. {
  42. return (double.Parse(Calc(n.Substring(0, n.IndexOf('+')))) + double.Parse(Calc(n.Substring(n.IndexOf('+') + 1)))).ToString();
  43. }
  44.  
  45. else if (n.Contains("*"))
  46. {
  47. return (double.Parse(Calc(n.Substring(0, n.IndexOf('*')))) * double.Parse(Calc(n.Substring(n.IndexOf('*') + 1)))).ToString();
  48. }
  49. else if (n.Contains("/"))
  50. {
  51. return (double.Parse(Calc(n.Substring(0, n.IndexOf('/')))) / double.Parse(Calc(n.Substring(n.IndexOf('/') + 1)))).ToString();
  52. }
  53. else if (n.Contains("^"))
  54. {
  55. return (Math.Pow(double.Parse(Calc(n.Substring(0, n.IndexOf('^')))), double.Parse(Calc(n.Substring(n.IndexOf('^') + 1))))).ToString();
  56. }
  57. else //if (n.Contains("√"))
  58. {
  59. n = n.Remove(n.IndexOf("√"), 1);
  60.  
  61. return (Math.Sqrt(double.Parse(Calc(n)))).ToString();
  62. }
  63.  
  64. }
  65. else
  66. return n;
  67. }
  68. private void Equal(object sender, EventArgs e)
  69. {
  70. textBox1.Text = Calc(textBox1.Text);
  71. }
  72.  
  73. private void button1_Click_1(object sender, EventArgs e)//-
  74. {
  75. textBox1.Text += "-";
  76. textBox1.CursorChanged += button1_Click_1;
  77. }
  78.  
  79. private void button2_Click(object sender, EventArgs e)//+
  80. {
  81. textBox1.Text += "+";
  82. }
  83.  
  84. private void button3_Click(object sender, EventArgs e)//*
  85. {
  86. textBox1.Text += "*";
  87. }
  88.  
  89. private void button4_Click(object sender, EventArgs e)///
  90. {
  91. textBox1.Text += "/";
  92. }
  93.  
  94. private void button5_Click(object sender, EventArgs e)//^
  95. {
  96. textBox1.Text += "^";
  97. }
  98.  
  99. private void button8_Click(object sender, EventArgs e)
  100. {
  101. textBox1.Text += ")";
  102. }
  103.  
  104. private void button9_Click(object sender, EventArgs e)
  105. {
  106. textBox1.Text += "(";
  107. }
  108.  
  109. private void button6_Click(object sender, EventArgs e)//√
  110. {
  111. textBox1.Text += "√";
  112.  
  113. }
  114. }
  115. }
  116.  
  117.  
  118.  
  119. ------------------
  120.  
  121.  
  122.  
  123. namespace WindowsFormsApp1
  124. {
  125. partial class Form1
  126. {
  127. /// <summary>
  128. /// Required designer variable.
  129. /// </summary>
  130. private System.ComponentModel.IContainer components = null;
  131.  
  132. /// <summary>
  133. /// Clean up any resources being used.
  134. /// </summary>
  135. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  136. protected override void Dispose(bool disposing)
  137. {
  138. if (disposing && (components != null))
  139. {
  140. components.Dispose();
  141. }
  142. base.Dispose(disposing);
  143. }
  144.  
  145. #region Windows Form Designer generated code
  146.  
  147. /// <summary>
  148. /// Required method for Designer support - do not modify
  149. /// the contents of this method with the code editor.
  150. /// </summary>
  151. private void InitializeComponent()
  152. {
  153. this.components = new System.ComponentModel.Container();
  154. this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
  155. this.azToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  156. this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
  157. this.azToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  158. this.textBox1 = new System.Windows.Forms.TextBox();
  159. this.button1 = new System.Windows.Forms.Button();
  160. this.button2 = new System.Windows.Forms.Button();
  161. this.button3 = new System.Windows.Forms.Button();
  162. this.button4 = new System.Windows.Forms.Button();
  163. this.button5 = new System.Windows.Forms.Button();
  164. this.button6 = new System.Windows.Forms.Button();
  165. this.button7 = new System.Windows.Forms.Button();
  166. this.button8 = new System.Windows.Forms.Button();
  167. this.button9 = new System.Windows.Forms.Button();
  168. this.SuspendLayout();
  169. //
  170. // contextMenuStrip1
  171. //
  172. this.contextMenuStrip1.Name = "contextMenuStrip1";
  173. this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
  174. //
  175. // azToolStripMenuItem
  176. //
  177. this.azToolStripMenuItem.Name = "azToolStripMenuItem";
  178. this.azToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
  179. //
  180. // toolStripComboBox1
  181. //
  182. this.toolStripComboBox1.Name = "toolStripComboBox1";
  183. this.toolStripComboBox1.Size = new System.Drawing.Size(121, 23);
  184. //
  185. // azToolStripMenuItem1
  186. //
  187. this.azToolStripMenuItem1.Name = "azToolStripMenuItem1";
  188. this.azToolStripMenuItem1.Size = new System.Drawing.Size(32, 19);
  189. //
  190. // textBox1
  191. //
  192. this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F);
  193. this.textBox1.Location = new System.Drawing.Point(232, 59);
  194. this.textBox1.Multiline = true;
  195. this.textBox1.Name = "textBox1";
  196. this.textBox1.Size = new System.Drawing.Size(306, 68);
  197. this.textBox1.TabIndex = 2;
  198. this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  199. this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  200. //
  201. // button1
  202. //
  203. this.button1.Location = new System.Drawing.Point(232, 188);
  204. this.button1.Name = "button1";
  205. this.button1.Size = new System.Drawing.Size(72, 49);
  206. this.button1.TabIndex = 3;
  207. this.button1.Text = "-";
  208. this.button1.UseVisualStyleBackColor = true;
  209. this.button1.Click += new System.EventHandler(this.button1_Click_1);
  210. //
  211. // button2
  212. //
  213. this.button2.Location = new System.Drawing.Point(310, 188);
  214. this.button2.Name = "button2";
  215. this.button2.Size = new System.Drawing.Size(72, 49);
  216. this.button2.TabIndex = 4;
  217. this.button2.Text = "+";
  218. this.button2.UseVisualStyleBackColor = true;
  219. this.button2.Click += new System.EventHandler(this.button2_Click);
  220. //
  221. // button3
  222. //
  223. this.button3.Location = new System.Drawing.Point(388, 188);
  224. this.button3.Name = "button3";
  225. this.button3.Size = new System.Drawing.Size(72, 49);
  226. this.button3.TabIndex = 5;
  227. this.button3.Text = "*";
  228. this.button3.UseVisualStyleBackColor = true;
  229. this.button3.Click += new System.EventHandler(this.button3_Click);
  230. //
  231. // button4
  232. //
  233. this.button4.Location = new System.Drawing.Point(466, 188);
  234. this.button4.Name = "button4";
  235. this.button4.Size = new System.Drawing.Size(72, 49);
  236. this.button4.TabIndex = 6;
  237. this.button4.Text = "/";
  238. this.button4.UseVisualStyleBackColor = true;
  239. this.button4.Click += new System.EventHandler(this.button4_Click);
  240. //
  241. // button5
  242. //
  243. this.button5.Location = new System.Drawing.Point(232, 243);
  244. this.button5.Name = "button5";
  245. this.button5.Size = new System.Drawing.Size(72, 49);
  246. this.button5.TabIndex = 7;
  247. this.button5.Text = "^";
  248. this.button5.UseVisualStyleBackColor = true;
  249. this.button5.Click += new System.EventHandler(this.button5_Click);
  250. //
  251. // button6
  252. //
  253. this.button6.Location = new System.Drawing.Point(310, 243);
  254. this.button6.Name = "button6";
  255. this.button6.Size = new System.Drawing.Size(72, 49);
  256. this.button6.TabIndex = 8;
  257. this.button6.Text = "√";
  258. this.button6.UseVisualStyleBackColor = true;
  259. this.button6.Click += new System.EventHandler(this.button6_Click);
  260. //
  261. // button7
  262. //
  263. this.button7.Location = new System.Drawing.Point(388, 243);
  264. this.button7.Name = "button7";
  265. this.button7.Size = new System.Drawing.Size(150, 49);
  266. this.button7.TabIndex = 9;
  267. this.button7.Text = "=";
  268. this.button7.UseVisualStyleBackColor = true;
  269. this.button7.Click += new System.EventHandler(this.Equal);
  270. //
  271. // button8
  272. //
  273. this.button8.Location = new System.Drawing.Point(388, 133);
  274. this.button8.Name = "button8";
  275. this.button8.Size = new System.Drawing.Size(150, 49);
  276. this.button8.TabIndex = 11;
  277. this.button8.Text = ")";
  278. this.button8.UseVisualStyleBackColor = true;
  279. this.button8.Click += new System.EventHandler(this.button8_Click);
  280. //
  281. // button9
  282. //
  283. this.button9.Location = new System.Drawing.Point(232, 133);
  284. this.button9.Name = "button9";
  285. this.button9.Size = new System.Drawing.Size(150, 49);
  286. this.button9.TabIndex = 10;
  287. this.button9.Text = "(";
  288. this.button9.UseVisualStyleBackColor = true;
  289. this.button9.Click += new System.EventHandler(this.button9_Click);
  290. //
  291. // Form1
  292. //
  293. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  294. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  295. this.ClientSize = new System.Drawing.Size(800, 450);
  296. this.Controls.Add(this.button8);
  297. this.Controls.Add(this.button9);
  298. this.Controls.Add(this.button7);
  299. this.Controls.Add(this.button6);
  300. this.Controls.Add(this.button5);
  301. this.Controls.Add(this.button4);
  302. this.Controls.Add(this.button3);
  303. this.Controls.Add(this.button2);
  304. this.Controls.Add(this.button1);
  305. this.Controls.Add(this.textBox1);
  306. this.Name = "Form1";
  307. this.Text = "Form1";
  308. this.ResumeLayout(false);
  309. this.PerformLayout();
  310.  
  311. }
  312.  
  313. #endregion
  314.  
  315. private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
  316. private System.Windows.Forms.ToolStripMenuItem azToolStripMenuItem;
  317. private System.Windows.Forms.ToolStripComboBox toolStripComboBox1;
  318. private System.Windows.Forms.ToolStripMenuItem azToolStripMenuItem1;
  319. private System.Windows.Forms.TextBox textBox1;
  320. private System.Windows.Forms.Button button1;
  321. private System.Windows.Forms.Button button2;
  322. private System.Windows.Forms.Button button3;
  323. private System.Windows.Forms.Button button4;
  324. private System.Windows.Forms.Button button5;
  325. private System.Windows.Forms.Button button6;
  326. private System.Windows.Forms.Button button7;
  327. private System.Windows.Forms.Button button8;
  328. private System.Windows.Forms.Button button9;
  329. }
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement