Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.59 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 calculator
  12. {
  13.  
  14.    
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void button4_Click(object sender, EventArgs e)
  23.         {
  24.             textBox1.Text += "7";
  25.         }
  26.  
  27.         private void button3_Click(object sender, EventArgs e)
  28.         {
  29.             textBox1.Text += "8";
  30.         }
  31.  
  32.         private void button2_Click(object sender, EventArgs e)
  33.         {
  34.             textBox1.Text += "9";
  35.         }
  36.  
  37.         private void button5_Click(object sender, EventArgs e)
  38.         {
  39.             textBox1.Text += "4";
  40.         }
  41.  
  42.         private void button6_Click(object sender, EventArgs e)
  43.         {
  44.             textBox1.Text += "5";
  45.         }
  46.  
  47.         private void button7_Click(object sender, EventArgs e)
  48.         {
  49.             textBox1.Text += "6";
  50.         }
  51.  
  52.         private void button9_Click(object sender, EventArgs e)
  53.         {
  54.             textBox1.Text += "1";
  55.         }
  56.  
  57.         private void button10_Click(object sender, EventArgs e)
  58.         {
  59.             textBox1.Text += "2";
  60.         }
  61.  
  62.         private void button11_Click(object sender, EventArgs e)
  63.         {
  64.             textBox1.Text += "3";
  65.         }
  66.  
  67.         private void button13_Click(object sender, EventArgs e)
  68.         {
  69.             textBox1.Text += "^";
  70.         }
  71.  
  72.         private void button14_Click(object sender, EventArgs e)
  73.         {
  74.             textBox1.Text += "0";
  75.         }
  76.  
  77.         private void button1_Click(object sender, EventArgs e)
  78.         {
  79.             textBox1.Text += "+";
  80.         }
  81.  
  82.         private void button8_Click(object sender, EventArgs e)
  83.         {
  84.             textBox1.Text += "-";
  85.         }
  86.  
  87.         private void button12_Click(object sender, EventArgs e)
  88.         {
  89.             textBox1.Text += "*";
  90.         }
  91.  
  92.         private void button16_Click(object sender, EventArgs e)
  93.         {
  94.             textBox1.Text += "/";
  95.         }
  96.         private void button20_Click(object sender, EventArgs e)
  97.         {
  98.             textBox1.Text += "√";
  99.         }
  100.  
  101.         private void button15_Click(object sender, EventArgs e)
  102.         {
  103.             try
  104.             {
  105.                             int t = 0;
  106.             if (textBox1.Text.Contains("+"))
  107.             {
  108.                 t = textBox1.Text.IndexOf("+");
  109.             }
  110.             else if (textBox1.Text.Contains("-"))
  111.             {
  112.                 t = textBox1.Text.IndexOf("-");
  113.             }
  114.             else if (textBox1.Text.Contains("*"))
  115.             {
  116.                 t = textBox1.Text.IndexOf("*");
  117.             }
  118.             else if (textBox1.Text.Contains("/"))
  119.             {
  120.                 t = textBox1.Text.IndexOf("/");
  121.             }
  122.                 else if (textBox1.Text.Contains("^"))
  123.                 {
  124.                     t = textBox1.Text.IndexOf("^");
  125.                 }
  126.                 else if (textBox1.Text.Contains("√"))
  127.                 {
  128.                     t = textBox1.Text.IndexOf("√");
  129.                 }
  130.  
  131.                 string x = textBox1.Text.Substring(t,1);
  132.             double x1 = Convert.ToDouble(textBox1.Text.Substring(0,t));
  133.             double x2 = Convert.ToDouble(textBox1.Text.Substring(t+1,textBox1.Text.Length-t-1));
  134.             if (x == "+")
  135.             {
  136.                 listBox1.Items.Add(textBox1.Text + "=" + (x1 + x2));
  137.                 textBox1.Text = (x1 + x2).ToString();
  138.             }
  139.             else if (x == "-")
  140.             {
  141.                 listBox1.Items.Add(textBox1.Text + "=" + (x1 - x2));
  142.                 textBox1.Text = (x1 - x2).ToString();
  143.             }
  144.             else if (x == "*")
  145.             {
  146.                 listBox1.Items.Add(textBox1.Text + "=" + (x1 * x2));
  147.                 textBox1.Text = (x1 * x2).ToString();
  148.             }
  149.             else if (x == "/")
  150.             {
  151.                 listBox1.Items.Add(textBox1.Text + "=" + (x1 / x2));
  152.                 textBox1.Text = (x1 /x2).ToString();
  153.             }
  154.                 else if (x == "^")
  155.                 {
  156.                     listBox1.Items.Add(textBox1.Text + "=" + Math.Pow(x1 , x2));
  157.                     textBox1.Text = Math.Pow(x1 , x2).ToString();
  158.                 }
  159.                 else if (x == "√")
  160.                 {
  161.                     listBox1.Items.Add(textBox1.Text + "=" + Math.Pow(x1,1 / x2));
  162.                     textBox1.Text = Math.Pow(x1,1 / x2).ToString();
  163.                 }
  164.  
  165.             }
  166.             catch
  167.             {
  168.  
  169.                 textBox1.Text = "error";
  170.             }
  171.         }
  172.  
  173.         private void button17_Click(object sender, EventArgs e)
  174.         {
  175.             textBox1.Text = "";
  176.         }
  177.  
  178.         private void Form1_Load(object sender, EventArgs e)
  179.         {
  180.  
  181.         }
  182.  
  183.         private void button18_Click(object sender, EventArgs e)
  184.         {
  185.             using (System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(@"C:\Users\admin\Desktop\calculator\Logi.txt"))
  186.             {
  187.                 foreach (var item in listBox1.Items)
  188.                 {
  189.                     SaveFile.WriteLine(item.ToString());
  190.                 }
  191.             }
  192.         }
  193.  
  194.         private void editLast_Click(object sender, EventArgs e)
  195.         {
  196.             textBox1.Text = listBox1.Items[listBox1.Items.Count - 1].ToString();
  197.             listBox1.Items.RemoveAt(listBox1.Items.Count - 1);
  198.         }
  199.     }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement