Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Thursday, 8 October 2015

Calculator Program In C#

 No comments   

Introduction

A basic Calculator program which is written in C# by using various Window Form Controls.
Calculator performs Addition, Subtraction, Division, Multiplication , Square Root, Power and find Absolute value on given input numbers.

Calculator Design View On Window Form


C# Code(On Code-Behind Window)

namespace Calculator1ByJatin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       
        double value = 0;
        double no2 = 0;
        bool OperatorPress = false;
        string operationPerformed = "";
               // Function Check For Point 
        public bool CheckForType()
        {
            char[] arr = txtmsg.Text.ToCharArray();
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] == '.')
                    return true;
            }
            return false;
        }

        private void BtnAll(object sender, EventArgs e)
        {
            if ((txtmsg.Text == "0") || (OperatorPress))
                txtmsg.Clear();

                OperatorPress = false;
                Button b = (Button)sender;
                txtmsg.Text += b.Text;
        }

       private void btnCE_Click(object sender, EventArgs e)
        {
            txtmsg.Text = "0";
            value = 0;
            label2.Text = "";
        }
                 // Single event for all alphatbets.
        private void BtnAllOperator(object sender, EventArgs e)
        {
            if (value != 0)
            {
                btnequals.PerformClick();
                Button b = (Button)sender;
                operationPerformed = b.Text;
                value = Convert.ToDouble(txtmsg.Text);
                label2.Text += value + " " + operationPerformed;
                OperatorPress = true;
              //  pow = true;
            }
            else
            {
                Button b = (Button)sender;
                operationPerformed = b.Text;
                value = Convert.ToDouble(txtmsg.Text);
             label2.Text += value + " " + operationPerformed;
                OperatorPress = true;
            //    pow = true;
            }
         
        }

        private void btnZero_Click(object sender, EventArgs e)
        {
            if (txtmsg.Text != "0")
                txtmsg.Text += btnZero.Text;
            else
                txtmsg.Text = btnZero.Text;
        }

        private void btnDot_Click(object sender, EventArgs e)
        {
            if (txtmsg.Text == "")
                txtmsg.Text = "0.";
            else
                if (!CheckForType())
                    txtmsg.Text += btnDot.Text;
        }


        private void btnequals_Click(object sender, EventArgs e)
        {
            switch(operationPerformed)
            {
                case "+" :
                   
            txtmsg.Text= (value+Convert.ToDouble(txtmsg.Text)).ToString();
                break;
                case "-":
             txtmsg.Text=(value-Convert.ToDouble(txtmsg.Text)).ToString();
             break;
                case "*":
                    txtmsg.Text=(value*Convert.ToDouble(txtmsg.Text)).ToString();
                break;
                case "/":
                    txtmsg.Text=(value/Convert.ToDouble(txtmsg.Text)).ToString();
                break;
                case "Power":
                txtmsg.Text = (Math.Pow(value, Convert.ToDouble(txtmsg.Text))).ToString();
                break;
            }
            value = Convert.ToDouble(txtmsg.Text);
           
            label2.Text = "";
        }

        private void btnOff_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnback_Click(object sender, EventArgs e)
        {
            txtmsg.Text = txtmsg.Text.Remove(txtmsg.Text.Length - 1);
        }
   
     
        private void btnsqrt_Click(object sender, EventArgs e)
        {
            value = double.Parse(txtmsg.Text);
            no2 = Math.Sqrt(value);
            txtmsg.Text = no2.ToString();
            no2 = 0;
        }

        private void btnAbs_Click(object sender, EventArgs e)
        {

            value = double.Parse(txtmsg.Text);
            no2 = Math.Truncate(value);
            txtmsg.Text = no2.ToString();
            no2 = 0;
        }
        double m = 0;

        private void btnmplus_Click(object sender, EventArgs e)
        {
            m = double.Parse(txtmsg.Text);
            if(txtmsg.Text!="0")
            label4.Text = "M";
          
        }

        private void btnmr_Click(object sender, EventArgs e)
        {
            if (m > 0)
                txtmsg.Text = m.ToString();
        }

        private void btnmc_Click(object sender, EventArgs e)
        {
            m = 0;
            label4.Text = "";
        }
     
    }
}
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Popular Posts

  • Base64 Encoding And Decoding In SQL Server
    Introduction In this article we will learn How to encode a string into Base64String and how to decode Base64String to string. How to crea...
  • Convert DataSet To List Or GenericList Using LINQ - C#
    Introduction In this article we will learn how to convert dataset to list or convert DataSet to List of collection o generic list in c#. ...
  • Trigger In SQL Server - Insert Update Delete In Single Trigger With Example
    Introduction In this article we will learn what is trigger . How to manage Insert, Update and Delete operation in trigger. Insert Update ...
  • Maintain The State Of Dynamic Added User Control On Each PostBack
    Introduction In this article we will learn how to maintain the state of dynamically created controls in asp.net using c#.  Retain the stat...
  • What Is Connection Pooling In Asp.Net Using C# With Example
    Introduction In this article we will learn what is connection pooling. Why connection pooling useful , what is the max limit and minimum ...

Categories

comma seperated string in sql Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS row_number() and dense_rank() salary table structure. Scope_Identity() Use of indexes while loop in sql why do we need cursor why tuple used

Best Deal Here

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write