Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- double f, s;
- double sum;
- bool root = false;
- public Form1()
- {
- InitializeComponent();
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- public string Calc(string n)
- {
- if (n.Contains("-") || n.Contains("+") || n.Contains("*") || n.Contains("/") || n.Contains("^") || n.Contains("√") || n.Contains("("))
- {
- if (n.Contains("("))
- {
- return n = Calc((n.Substring(0,n.IndexOf('(')))+Calc(n.Substring(n.IndexOf('(') + 1, (n.IndexOf(')') - n.IndexOf('(') - 1)))+n.Substring(n.IndexOf(')') + 1));
- }
- if (n.Contains("-"))
- {
- return (double.Parse(Calc(n.Substring(0, n.IndexOf('-')))) - double.Parse(Calc(n.Substring(n.IndexOf('-') + 1)))).ToString();
- }
- else if (n.Contains("+"))
- {
- return (double.Parse(Calc(n.Substring(0, n.IndexOf('+')))) + double.Parse(Calc(n.Substring(n.IndexOf('+') + 1)))).ToString();
- }
- else if (n.Contains("*"))
- {
- return (double.Parse(Calc(n.Substring(0, n.IndexOf('*')))) * double.Parse(Calc(n.Substring(n.IndexOf('*') + 1)))).ToString();
- }
- else if (n.Contains("/"))
- {
- return (double.Parse(Calc(n.Substring(0, n.IndexOf('/')))) / double.Parse(Calc(n.Substring(n.IndexOf('/') + 1)))).ToString();
- }
- else if (n.Contains("^"))
- {
- return (Math.Pow(double.Parse(Calc(n.Substring(0, n.IndexOf('^')))), double.Parse(Calc(n.Substring(n.IndexOf('^') + 1))))).ToString();
- }
- else //if (n.Contains("√"))
- {
- n = n.Remove(n.IndexOf("√"), 1);
- return (Math.Sqrt(double.Parse(Calc(n)))).ToString();
- }
- }
- else
- return n;
- }
- private void Equal(object sender, EventArgs e)
- {
- textBox1.Text = Calc(textBox1.Text);
- }
- private void button1_Click_1(object sender, EventArgs e)//-
- {
- textBox1.Text += "-";
- textBox1.CursorChanged += button1_Click_1;
- }
- private void button2_Click(object sender, EventArgs e)//+
- {
- textBox1.Text += "+";
- }
- private void button3_Click(object sender, EventArgs e)//*
- {
- textBox1.Text += "*";
- }
- private void button4_Click(object sender, EventArgs e)///
- {
- textBox1.Text += "/";
- }
- private void button5_Click(object sender, EventArgs e)//^
- {
- textBox1.Text += "^";
- }
- private void button8_Click(object sender, EventArgs e)
- {
- textBox1.Text += ")";
- }
- private void button9_Click(object sender, EventArgs e)
- {
- textBox1.Text += "(";
- }
- private void button6_Click(object sender, EventArgs e)//√
- {
- textBox1.Text += "√";
- }
- }
- }
- ------------------
- namespace WindowsFormsApp1
- {
- partial class Form1
- {
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
- this.azToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
- this.azToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.button1 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.button6 = new System.Windows.Forms.Button();
- this.button7 = new System.Windows.Forms.Button();
- this.button8 = new System.Windows.Forms.Button();
- this.button9 = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // contextMenuStrip1
- //
- this.contextMenuStrip1.Name = "contextMenuStrip1";
- this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
- //
- // azToolStripMenuItem
- //
- this.azToolStripMenuItem.Name = "azToolStripMenuItem";
- this.azToolStripMenuItem.Size = new System.Drawing.Size(32, 19);
- //
- // toolStripComboBox1
- //
- this.toolStripComboBox1.Name = "toolStripComboBox1";
- this.toolStripComboBox1.Size = new System.Drawing.Size(121, 23);
- //
- // azToolStripMenuItem1
- //
- this.azToolStripMenuItem1.Name = "azToolStripMenuItem1";
- this.azToolStripMenuItem1.Size = new System.Drawing.Size(32, 19);
- //
- // textBox1
- //
- this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F);
- this.textBox1.Location = new System.Drawing.Point(232, 59);
- this.textBox1.Multiline = true;
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(306, 68);
- this.textBox1.TabIndex = 2;
- this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
- this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(232, 188);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(72, 49);
- this.button1.TabIndex = 3;
- this.button1.Text = "-";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click_1);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(310, 188);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(72, 49);
- this.button2.TabIndex = 4;
- this.button2.Text = "+";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(388, 188);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(72, 49);
- this.button3.TabIndex = 5;
- this.button3.Text = "*";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(466, 188);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(72, 49);
- this.button4.TabIndex = 6;
- this.button4.Text = "/";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(232, 243);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(72, 49);
- this.button5.TabIndex = 7;
- this.button5.Text = "^";
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // button6
- //
- this.button6.Location = new System.Drawing.Point(310, 243);
- this.button6.Name = "button6";
- this.button6.Size = new System.Drawing.Size(72, 49);
- this.button6.TabIndex = 8;
- this.button6.Text = "√";
- this.button6.UseVisualStyleBackColor = true;
- this.button6.Click += new System.EventHandler(this.button6_Click);
- //
- // button7
- //
- this.button7.Location = new System.Drawing.Point(388, 243);
- this.button7.Name = "button7";
- this.button7.Size = new System.Drawing.Size(150, 49);
- this.button7.TabIndex = 9;
- this.button7.Text = "=";
- this.button7.UseVisualStyleBackColor = true;
- this.button7.Click += new System.EventHandler(this.Equal);
- //
- // button8
- //
- this.button8.Location = new System.Drawing.Point(388, 133);
- this.button8.Name = "button8";
- this.button8.Size = new System.Drawing.Size(150, 49);
- this.button8.TabIndex = 11;
- this.button8.Text = ")";
- this.button8.UseVisualStyleBackColor = true;
- this.button8.Click += new System.EventHandler(this.button8_Click);
- //
- // button9
- //
- this.button9.Location = new System.Drawing.Point(232, 133);
- this.button9.Name = "button9";
- this.button9.Size = new System.Drawing.Size(150, 49);
- this.button9.TabIndex = 10;
- this.button9.Text = "(";
- this.button9.UseVisualStyleBackColor = true;
- this.button9.Click += new System.EventHandler(this.button9_Click);
- //
- // Form1
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Controls.Add(this.button8);
- this.Controls.Add(this.button9);
- this.Controls.Add(this.button7);
- this.Controls.Add(this.button6);
- this.Controls.Add(this.button5);
- this.Controls.Add(this.button4);
- this.Controls.Add(this.button3);
- this.Controls.Add(this.button2);
- this.Controls.Add(this.button1);
- this.Controls.Add(this.textBox1);
- this.Name = "Form1";
- this.Text = "Form1";
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
- private System.Windows.Forms.ToolStripMenuItem azToolStripMenuItem;
- private System.Windows.Forms.ToolStripComboBox toolStripComboBox1;
- private System.Windows.Forms.ToolStripMenuItem azToolStripMenuItem1;
- private System.Windows.Forms.TextBox textBox1;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.Button button3;
- private System.Windows.Forms.Button button4;
- private System.Windows.Forms.Button button5;
- private System.Windows.Forms.Button button6;
- private System.Windows.Forms.Button button7;
- private System.Windows.Forms.Button button8;
- private System.Windows.Forms.Button button9;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement