Friday 22 February 2013

CREATING OF CALCULATOR IN C# .NET


CODE OF CALCULATOR



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;








using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace calcuatoerqwe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "1";
            }
            button19.ForeColor = Color.Blue;
            button19.BackColor = Color.Yellow;
          
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "2";
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "3";
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "4";
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "5";
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "6";
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "7";
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "8";
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + "9";
            }
        }

        private void button17_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {

                textBox1.Text = textBox1.Text + "0";
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {
            if (textBox1.ReadOnly == false)
            {
                textBox1.Text = textBox1.Text + ".";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //textBox1.Clear();
            textBox1.Text = "";
        }
        double a, b, c;
        int aa;
        private void button12_Click(object sender, EventArgs e)
        {
            a = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();
            aa = 1;
        }

        private void button13_Click(object sender, EventArgs e)
        {
            a = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();
            aa = 2;
        }

        private void button14_Click(object sender, EventArgs e)
        {

            a = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();
            aa = 3;

        }

        private void button15_Click(object sender, EventArgs e)
        {

            a = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();
            aa = 4;
        }

        private void button16_Click(object sender, EventArgs e)
        {
            b = Convert.ToDouble(textBox1.Text);
            textBox1.Clear();

            switch (aa)
            {
                case 1:
                    {
                        c = a + b;
                        textBox1.Text = c.ToString();
                        break;
                    }
                case 2:
                    {
                        c = a - b;
                        textBox1.Text = c.ToString();
                        break;
                    }
                case 3:
                    {
                        c = a * b;
                        textBox1.Text = c.ToString();
                        break;
                    }
                case 4:
                    {
                        c = a / b;
                        textBox1.Text = c.ToString();
                        break;

                    }
            }
        }
  …./// back space

        private void button2_Click(object sender, EventArgs e)
        {
            int a = textBox1.Text.Length;
            string s = textBox1.Text;
            textBox1.Clear();
            for (int i = 0; i < a - 1; i++)
            {
                textBox1.Text = textBox1.Text + s[i].ToString();
            }
        }

        private void button19_Click(object sender, EventArgs e)
        {
            textBox1.ReadOnly = false;
        }

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

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(!char.IsDigit(e.KeyChar))
            {
                e.Handled=true;
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void button21_Click(object sender, EventArgs e)
        {
            a = Convert.ToDouble(textBox1.Text);
            textBox1.Text = Math.Sqrt(a).ToString();
        }

        private void button19_MouseHover(object sender, EventArgs e)
        {
            button19.Text = "please click me";
        }

        private void button19_MouseLeave(object sender, EventArgs e)
        {
            button19.Text = "on";
        }
    }
}



  string s = textBox1.Text;
            int aa = textBox1.Text.Length;
            textBox2.Clear();
            for (int a = aa-1; a >=0; a--)
            {
                textBox2.Text = textBox2.Text + (s[a].ToString());
            }

            if (textBox1.Text == textBox2.Text)
            {
                MessageBox.Show("no. is palindrom");
            }
            else
            {
                MessageBox.Show("no. is not palindrom");
            }

// decimal to binary

  int b, c;
        string j = "";
        string p = "";
        private void button1_Click(object sender, EventArgs e)
        {
            int a = Convert.ToInt32(textBox1.Text);
            while (a > 0)
            {
                b = a % 2;
                c = a / 2;
                a = c;
                j += b.ToString();
               // a--;
            }
            int l = j.Length;
            for(int i=l-1;i>=0;i--)
            {

                p += j[i].ToString();
            }
            textBox2.Text = p.ToString();
          
        }
//Binary to decimal

        private void button2_Click(object sender, EventArgs e)
        {
            double p=0;
            int l = textBox2.Text.Length;
            string s=textBox2.Text;
            for (int i = 0; i < l; i++)
            {
                p += Convert.ToDouble(s[i].ToString()) * Math.Pow(2, Convert.ToDouble(l - (i + 1)));
            }
            textBox3.Text = p.ToString();
        }
    }
}





No comments:

Post a Comment