I made a basic calculator using visual studio, DotNet & C#



Basic calculator using DotNet and C#


Simple calculator using DotNet Technology and C#


I made this simple mini-calculator project for my BCA 5th semester assignment. I have provided the source code.

An icon used: Icon Archive


Functions of this projects

  • Basic calculations like addition, subtraction, multiplication, and division.

  • GUI is made from windows form (DotNet framework).

Source Code





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

namespace myCalculator
{
    public partial class Form1 : Form
    {
        Double resultValue = 0;
        string operationPerformd = "";
        bool isoperationIsPerformed = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void button_click(object sender, EventArgs e)
        {

            if ((textBox_Result.Text == "0") || (isoperationIsPerformed))
            
                textBox_Result.Clear();
            
            isoperationIsPerformed = false;
            Button button = (Button)sender; //capture the event of all buttons
            if (button.Text == ".")
            {
                if (!textBox_Result.Text.Contains("."))
                    textBox_Result.Text = textBox_Result.Text + button.Text;
            }
            else
            {
                textBox_Result.Text = textBox_Result.Text + button.Text;
            }
            
        }

        private void operator_click(object sender, EventArgs e)
        {
            Button button = (Button)sender; //capture the event of all buttons

            if (resultValue != 0)
            {
                button28.PerformClick();
                operationPerformd = button.Text;
                textUpperLabel.Text = resultValue + " " + operationPerformd;
                isoperationIsPerformed = true;
            }
            else
            {
                operationPerformd = button.Text;
                resultValue = Double.Parse(textBox_Result.Text);
                textUpperLabel.Text = resultValue + " " + operationPerformd;
                isoperationIsPerformed = true;
            }
        }
        private void button10_Click(object sender, EventArgs e)
        {
            textBox_Result.Text = "0";
        }

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

        private void button28_Click(object sender, EventArgs e)
        {
            switch (operationPerformd)
            {
                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);
            textUpperLabel.Text = "";
        }

        private void textUpperLabel_Click(object sender, EventArgs e)
        {

        }
    }
}






The output of the code

dotnet technology project output


dotnet technology project output



Helpful links for you as a dot net developer:





Post a Comment

0 Comments