Arithmetic Operations on two numbers

By Deepak Dwij Oct 17, 2011
In this blog we are going to write a windows forms application that helps us to calculate the two numbers.
Introduction:

Adding, subtraction, multiplication and division of two numbers with the help of two TextBoxes and result will  display in third TextBox by using window form.

Step 1: Open visual studio--> file menu-->new--> project--> then

image-ist.gif

Step 2: Take 3 TextBoxes one for input First number, other for second number and third one is for the result TextBox. Design the form as follows:

image1.gif

Step 3: Coding

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 Arithmetic
{
    public partial class ArthOperations : Form
    {
        public ArthOperations()
        {
            InitializeComponent();
            textBox3.Enabled = false;
        }
        private void add(object sender, EventArgs e)
        {
            float first;
            float second;
            float output;       
           first = Convert.ToInt32(textBox1.Text);    
           second = Convert.ToInt32(textBox2.Text);
           output = first + second;
           textBox3.Text=(output.ToString());
        }
 
          private void sub(object sender, EventArgs e)
       {
            float first;
            float second;
            float output;
            first = Convert.ToInt32(textBox1.Text);
            second = Convert.ToInt32(textBox2.Text);
            output = first - second;
            textBox3.Text = (output.ToString());
       }

         private void div(object sender, EventArgs e)
        {
            float first;
            float second;
            float output;
            first = Convert.ToInt32(textBox1.Text);
            second = Convert.ToInt32(textBox2.Text);
            output = first / second;
            textBox3.Text = (output.ToString());
        }
 
        private void mul(object sender, EventArgs e)     {
            float first;
          float second;
            float output;
            first = Convert.ToInt32(textBox1.Text);
            second = Convert.ToInt32(textBox2.Text);
            output = first * second;
            textBox3.Text = (output.ToString());
        }
 
        private void clear(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = ""

        }
    }
}

Step 4- Runnning  above code 

ADD BUTTON CLICK.

add.gif

SUB BUTTON CLICK.

sub.gif

DIVISION BUTTON CLICK.

div.gif

MULTIPLY BUTTON CLICK.

mul.gif

Deepak Dwij

Patience creates a creativity in itself & time to achieve your desired goals. I m very much passionate about playing cricket !!!

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs