Scientific Calculator...

Scientific Calculator...

Here are some namespaces which you will include

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


This is the coding for creating a scientific calculator



namespace calculator
{
    public partial class Form1 : Form
    {
        calc.Class1 obj = new calc.Class1();
        //calc.Class1 obj1 = new calc.Class1();
       
//Variables which you have to decalre

        string sign; double r = 0;
        double p;
        bool count = false;
        bool ff = false;
        string sign1;
        double d = 0; double temp;

        double s;
        bool check = false;
        public Form1()
        {
            InitializeComponent();
        }

        public void button1_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                ff = true;
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString(textBox1.Text + button1.Text);
        }

        public void button2_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button2.Text);
        }

        public void button3_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button3.Text);
        }

        public void button4_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button4.Text);
        }

        public void button5_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button5.Text);
        }

        public void button6_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button6.Text);
        }

        public void button7_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button7.Text);
        }

        public void button8_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button8.Text);
        }

        public void button9_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button9.Text);
        }

        public void button10_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }

            textBox1.Text = Convert.ToString(textBox1.Text + button10.Text);
        }
        /*public void button1_Click(object sender, EventArgs e)
        {
            i0f (check == true)
            {
                ff = true;
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString(textBox1.Text + button1.Text);
        }*/

        private void button11_Click(object sender, EventArgs e)
        {

            check = true;
            s = double.Parse(textBox1.Text);
            sign = Convert.ToString(button11.Text);
            if (ff == true)
            {
                p = double.Parse(textBox1.Text);
                textBox1.Text = Convert.ToString((r + p));
                r = double.Parse(textBox1.Text);

                ff = false;
            }

        }

        private void button12_Click(object sender, EventArgs e)
        {
            check = true;
            s = double.Parse(textBox1.Text);
            sign = Convert.ToString(button12.Text);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            check = true;
            s = double.Parse(textBox1.Text);
            sign = Convert.ToString(button13.Text);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            check = true;
            s = double.Parse(textBox1.Text);
            sign = Convert.ToString(button14.Text);
        }

        private void button15_Click(object sender, EventArgs e)
        {
            temp = double.Parse(textBox1.Text);

            textBox1.Text = Convert.ToString(obj.op(s, temp, sign));
        }

        private void button16_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }

        private void button17_Click(object sender, EventArgs e)
        {
            string st;
            st = textBox1.Text;
            textBox1.Text = st.Substring(0, st.Length - 1);
        }

        private void button18_Click(object sender, EventArgs e)
        {

            s = double.Parse(textBox1.Text);
            sign = button18.Text;
            textBox1.Text = (obj.op(s, sign).ToString());
        }

        private void button19_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString((textBox1.Text + button19.Text));
        }

        private void button20_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }

        private void button21_Click(object sender, EventArgs e)
        {
            s = double.Parse(textBox1.Text);
            sign = button21.Text.ToString();
            textBox1.Text = obj.op(s, sign).ToString();
        }

        private void button22_Click(object sender, EventArgs e)
        {
            s = double.Parse(textBox1.Text);
            textBox1.Text = Convert.ToString(obj.op(s));
        }

        private void button23_Click(object sender, EventArgs e)
        {
            temp = double.Parse(textBox1.Text);
            sign = button23.Text.ToString();
            textBox1.Text = Convert.ToString(obj.op(temp, s, sign));

        }

        private void button24_Click(object sender, EventArgs e)
        {
            temp = double.Parse(textBox1.Text);
            sign = button24.Text;
            textBox1.Text = obj.op(temp, sign).ToString();
        }

        private void button25_Click(object sender, EventArgs e)
        {
            temp = double.Parse(textBox1.Text);
            sign = button25.Text;
            textBox1.Text = obj.op(temp, sign).ToString();
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            //dec
            //if (count ==false)
            // {
            long temp1 = long.Parse(textBox1.Text);
            // sign1 = radioButton3.Text;


            textBox1.Text = Convert.ToString(obj.op(sign, temp1, sign1));
            // }
            /*else
                        {
                            string temp2=textBox1.Text.ToString();
                            sign1=radioButton3.Text;
                            textBox1.Text = obj.op(temp2, sign).ToString() ;
                            }*/


        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        { //bin
            sign = radioButton1.Text;

            //temp = double.Parse((textBox1.Text));
            // sign = radioButton1.Text;
            // double k = (obj.op(s, sign));
            // textBox1.Text = (obj.op(s, sign).ToString());
        }

        private void button33_Click(object sender, EventArgs e)
        {
            temp = int.Parse(textBox1.Text);
            sign = button33.Text;
            textBox1.Text = (obj.op(temp, sign)).ToString();
        }

        private void button34_Click(object sender, EventArgs e)
        {
            temp = double.Parse(textBox1.Text);
            sign = button34.Text;
            textBox1.Text = (obj.op(temp, sign)).ToString();
        }

        private void button35_Click(object sender, EventArgs e)
        {
            temp = double.Parse(textBox1.Text);
            sign = button35.Text;
            textBox1.Text = (obj.op(temp, sign)).ToString();
        }

        private void button36_Click(object sender, EventArgs e)
        {
            temp = int.Parse(textBox1.Text);
            sign = button36.Text;
            textBox1.Text = (obj.op(temp, sign)).ToString();

        }

        private void button37_Click(object sender, EventArgs e)
        {
            check = true;
            s = double.Parse(textBox1.Text);
            sign = button37.Text;
        }

        private void button38_Click(object sender, EventArgs e)
        {
            decimal k = 22 / 7m;
            textBox1.Text = Convert.ToString(k);
        }

        private void button39_Click(object sender, EventArgs e)
        {
            s = double.Parse(textBox1.Text);
            sign = button39.Text;
            textBox1.Text = (obj.op(s, sign).ToString());
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            //oct
            //temp = double.Parse(textBox1.Text);
            sign = radioButton2.Text;
            //textBox1.Text = (obj.op(temp, sign).ToString());
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {//hex
            //temp = double.Parse(textBox1.Text);
            //count = true;
            sign = radioButton4.Text;
            //textBox1.Text = (obj.op(temp, sign).ToString());

        }

        private void button27_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString(textBox1.Text + button27.Text);
        }

        private void button28_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString(textBox1.Text + button28.Text);
        }

        private void button29_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString(textBox1.Text + button29.Text);


        }

        private void button30_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString(textBox1.Text + button30.Text);
        }

        private void button31_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString(textBox1.Text + button31.Text);
        }

        private void button32_Click(object sender, EventArgs e)
        {
            if (check == true)
            {
                check = false;
                textBox1.Text = "";
            }
            textBox1.Text = Convert.ToString(textBox1.Text + button31.Text);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {

            System.Windows.Forms.DialogResult answer;
           
                answer = MessageBox.Show("Do you really want to exit_? ", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (answer == System.Windows.Forms.DialogResult.No)
                {
                    return;
                }
                else
                {
                    Application.Exit();

                }
            }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            abtfrm a = new abtfrm();
            a.Show();
        }
     }
}


Here is the Interface of Scientific Calculator__

Scientific Calculator.JPG

For further help :

Contact : [email protected]

Next Recommended Reading A fast and very simple calculator