Techknow Study

CALC in vb 2010 through c#

11:40:00 PM vikas 0 Comments Category :

Hay friends i give u simple help to design a simple calc in visual basic through c#.
i consider that you know how to work on designing phase.
so go on and make your own calc with your name, dimension.
you can also introduce your own feature in your calc.
so now start with this............
a simpe picture of my calc is.........



program
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 calvj
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        string a,c;
        double b,d;
        string opp;

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button1.Text;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button2.Text;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button3.Text;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button4.Text;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button5.Text;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button6.Text;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button7.Text;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button8.Text;
        }

        private void button9_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button9.Text;
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if(textBox1.Text.IndexOf(".")<0)
            {
                textBox1.Text = textBox1.Text + button10.Text;
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if(textBox1.Text!="")
            {
                textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
            }
            }

        private void button12_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + button12.Text;
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                a = textBox1.Text;
                textBox1.Text = "";
                b = Convert.ToDouble(a);
                opp = button13.Text;
            }
        }
        private void button14_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                a = textBox1.Text;
                textBox1.Text = "";
                b = Convert.ToDouble(a);
                opp = button14.Text;
            }
        }

        private void button15_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                a = textBox1.Text;
                textBox1.Text = "";
                b = Convert.ToDouble(a);
                opp = button15.Text;
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                a = textBox1.Text;
                textBox1.Text = "";
                b = Convert.ToDouble(a);
                opp = button16.Text;
            }
        }

        private void button17_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                a = textBox1.Text;
                b = Convert.ToDouble(a);
                textBox1.Text = (Math.Sqrt(b)).ToString();
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {
            a = textBox1.Text;
            textBox1.Text = "";
            b = Convert.ToDouble(a);
            opp = button18.Text;
        }

        private void button19_Click(object sender, EventArgs e)
        {
            a = textBox1.Text;
            b = Convert.ToDouble(a);
            b = 1 / b;
            textBox1.Text = Convert.ToString(b);
        }

        private void button20_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
        }
        private void button21_Click(object sender, EventArgs e)
        {
            result();
            opp = "";
            a = "";
            c= "";
           
        }
        private void result()
        {
            c = textBox1.Text;
            d = Convert.ToDouble(c);
            switch (opp)
            {
                case "+":
                    b = b + d;
                    break;
                case "-":
                    b = b - d;
                    break;
                case "*":
                    b = b * d;
                    break;
                case "/":
                    b = b / d;
                    break;
                case "%":
                    b = b % d;
                    break;
            }
            textBox1.Text = Convert.ToString(b);
        }  
    }
}

Guys if u want add this button on your  calc than coading for that is.....
below.......



 private void button22_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.IndexOf("-") < 0)
            {
                textBox1.Text = "-" + textBox1.Text;
            }
            else
            {

                textBox1.Text = textBox1.Text.Substring(1, textBox1.Text.Length - 1);
            }
        }



RELATED POSTS

0 comments