C Sharp 6.0

The new version of c sharp is quite easy to use as compared to previous versions. Developer has many options to quickly write a program.
































\\\\

Creating a Calculator step by step Final part -4

Here is final look of our calculator. You can customize your calculator according to your desire.



Creating a Calculator in C sharp


Creating a simple calculator step by step in C sharp -3

Make sure you have the following code in Program.cs.


Program.cs


using System;
using System.Windows.Forms;

namespace Calculator
{
    static class Program
    {
     
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Calculator());
        }
    }
}


In the next post I will show you the final part Calculator.


 Next:    Calculator Final part 4

eating a simple calculator step by step in C sharp -2


Copy and paste the following code in Form2.cs.


Form2.cs

using System;
using System.Windows.Forms;

namespace Calculator
{
    public partial class Calculator : Form
    {
        Double resultValue = 0;
        String operationPerformed = "";
        bool isOperationPerformed = false;
        public Calculator()
        {
            InitializeComponent();
        }

        private void button_Click(object sender, EventArgs e)
        {
            if ((textBox_Result.Text == "0") || (isOperationPerformed))
                textBox_Result.Clear();

            isOperationPerformed = false;
            Button button = (Button)sender;
            if(button.Text == ".")
            {
                if (textBox_Result.Text.Contains("."))
                    textBox_Result.Text = textBox_Result.Text + button.Text;
            }

            textBox_Result.Text = textBox_Result.Text + button.Text;
        }

        private void operator_click(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            if (resultValue != 0)
            {
                button11.PerformClick();
                operationPerformed = button.Text;
                labelCurrentOperation.Text = resultValue + " " + operationPerformed;
                isOperationPerformed = true;
            }
            else
            {
                operationPerformed = button.Text;
                resultValue = Double.Parse(textBox_Result.Text);
                labelCurrentOperation.Text = resultValue + " " + operationPerformed;
                isOperationPerformed = true;
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox_Result.Text = "0";
            resultValue = 0;

        }

        private void button11_Click(object sender, EventArgs e)
        {
            switch (operationPerformed)
            {
                case "+":
                    textBox_Result.Text = (resultValue + Double.Parse(textBox_Result.Text)).ToString();
                    break;
                case "-":
                    textBox_Result.Text = (resultValue - Double.Parse(textBox_Result.Text)).ToString();
                    break;
                case "*":
                    textBox_Result.Text = (resultValue * Double.Parse(textBox_Result.Text)).ToString();
                    break;
                case "/":
                    textBox_Result.Text = (resultValue / Double.Parse(textBox_Result.Text)).ToString();
                    break;
                default:
                    break;
            }
            resultValue = Double.Parse(textBox_Result.Text);
            labelCurrentOperation.Text = "";
        }
    }
}


In the next post I will show you complete coding of Program.cs step by step.


 Next:    Calculator code part 3







Creating a simple calculator in C sharp step by step Part -1


Lets start coding part of our calculator application.




Right click on the calculator in Solution Explorer on the right side of your screen. Then add new item.

Now you have successfully created your Form.









We are done with our designing of Calculator.

In the next post I will show you coding part.






In the next post I will show you complete Coding of Program.cs step by step.


 Next:    Calculator code part 2



























Creating a simple calculator in C sharp

It was never easy to make a calculator so easily. Lets start building our calculator.

Requirements

You need to install Visual Studio 2015. You can download it from following link.

https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx

after installing visual studios. just follow the following steps.

On the very first run you will see the following page.




Click the new project.




After selecting new project a window will open. Select Windows Forms Application.
Them name it calculator and press ok button to create your project.


























Infolinks In Text Ads

these