Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases > Coding Snippets
You last visited: Today at 06:46

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C# Windows Application Calculator (ADVANCED)

Discussion on C# Windows Application Calculator (ADVANCED) within the Coding Snippets forum part of the Coding Releases category.

Reply
 
Old   #1
 
v1suaL's Avatar
 
elite*gold: 0
Join Date: May 2014
Posts: 66
Received Thanks: 13
Thumbs up C# Windows Application Calculator (ADVANCED)

Don't forget to thank me.

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;
/*
 * Controls needed:
 * 18 buttons button 16 and 17 must be del and clear and button 15 MUST be =
 * 1 Textbox (read only true)
 * Mouse enter (buttons) to hoverON
 * Mouse leave (buttons) to hoverOFF
 * Button click (buttons) to buttonCheck
 * Button click(-+/x) to setOperator
*/
namespace Calculator
{
    public partial class Form1 : Form
    {
        int value1 = 0; //Declare old value
        int opValue = 0; //Declare operation value
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            //nothing has to be done here
        }
        //making a new void for the controls
        private void ButtonCheck(Object sender, EventArgs e)
        {
            
            if (display.MaxLength <= 20) //do this if maxlength is smaller then or equal to 20
            {
            if(display.Text == "Math Error"){ // if the math error is known clear the display
                display.Clear();
            }
            display.MaxLength += 1; //increase max length
            Button getSender = (Button)sender; //declare get sender with the button clicked options
            display.Text = display.Text + getSender.Text; //add the number in the screen
            }
        }
        private void button15_Click(object sender, EventArgs e)
        {
            int answer = 0;
            if(opValue == 0){ //if operator isn't set
                display.Text = "Math Error";
            }
            else if(display.Text == "") //if values isn't set
            {
                display.Text = "Math Error";
            }
            else if (display.Text == "Math Error") //if math error is shown
            {
                display.Text = "Math Error";
            } else if(opValue == 1){
                // - operator
                answer = value1 - Convert.ToInt32(display.Text); //calculate with -
                display.Text = answer.ToString(); //show the answer
            } else if(opValue == 2){ 
                // + operator
                answer = value1 + Convert.ToInt32(display.Text); //calculate with +
                display.Text = answer.ToString(); //show the answer
            } else if (opValue == 3){ 
                // / operator
                answer = value1 / Convert.ToInt32(display.Text); //calculate with /
                display.Text = answer.ToString(); //show the answer
            }
            else if (opValue == 4)
            {
                // * operator
                answer = value1 * Convert.ToInt32(display.Text); //calculate with *
                display.Text = answer.ToString(); //show the answer
            }
            else if (opValue == 5)
            {
                // ^ operator
                answer = Convert.ToInt32(System.Math.Pow(Convert.ToDouble(value1), Convert.ToDouble(display.Text))); //calculate with ^
                display.Text = answer.ToString(); //show the answer
            }
            answer = 0; //reset answer
            opValue = 0; //reset operator value
            value1 = 0; //reset old value
        }
        private void setOperator(Object sender, EventArgs e)
        {
            Button getSender = (Button)sender;
            if (getSender.Text == "-") //get -
            {
                opValue = 1; //set operator value
            }
            else if (getSender.Text == "+") //get +
            {
                opValue = 2; //set operator value
            }
            else if (getSender.Text == "/") //get /
            {
                opValue = 3; //set operator value
            }
            else if (getSender.Text == "x") //get x
            {
                opValue = 4; //set operator value
            }
            else if (getSender.Text == "^") //get ^
            {
                opValue = 5; //set operator value
            }
            else
            {
                display.Text = "Operator Error"; //show error
            }
            if (display.Text != "") //if display is empty
            {
                if (display.Text == "Math Error") //if match error shows
                {
                    display.Text = "Math Error"; //display math error
                }
                else
                {
                    value1 = Convert.ToInt32(display.Text); //set old value to new text
                    display.Clear(); //clear the display
                }
            }
            else
            {
                display.Text = "Math Error"; //display math error
            }
            
        }
        //del(delete) button
        private void button16_Click(object sender, EventArgs e)
        {
            if (display.Text.Length >= 1) //if current length is greater than or equal to 1
            {
                display.Text = display.Text.Remove(display.Text.Length - 1); //remove last character
            }
        }
        
        //c(clear) button
        private void button17_Click(object sender, EventArgs e)
        {
            display.Clear(); //clear the button
            value1 = 0;//reset old value
            opValue = 0;//reset operator value
        }
        //BUTTON HOVER\\
        //On mouse entering (over) a button
        private void button_HoverON(object sender, EventArgs e)
        {
            Button getButton = (Button)sender; //get button options
            getButton.BackColor = Color.LightGray; //set button background colour
        }
        //On mouse leaving (out) a button
        private void button_HoverOFF(object sender, EventArgs e)
        {
            Button getButton = (Button)sender; //get button options
            getButton.BackColor = Color.FromName("Control"); //set button background to default button colour
        }
    }
v1suaL is offline  
Thanks
1 User
Old 05/11/2014, 17:55   #2
 
elite*gold: 22
Join Date: Feb 2012
Posts: 576
Received Thanks: 332
Thank u for posting in the wrong section?
Thank u for posting work of 2min coding?
Thank u for this code?
No thank u.
VisionEP1 is offline  
Thanks
1 User
Old 05/18/2014, 17:13   #3

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
Received Thanks: 250
and thank you for distributing crappy written code, i hope no one will ever use this as a reference
x]vIrus[x is offline  
Reply


Similar Threads Similar Threads
Advanced DLL Injector (XP, Vista, Windows 7 64 Bit)
02/15/2013 - Coding Releases - 10 Replies
Hallo zusammen, anbei mein DLL Injector welchen ich auf XP, Vista und Windows 7 64 Bit getestet habe. Bei Fragen etc. könnt Ihr Euch gerne melden. MD5: fb7d161059eec4d4204818382b1d1ac5 Dateigröße: 450560 byte Cheers,
How I start my application with Windows ?
03/13/2012 - AutoIt - 12 Replies
English: Hello. I want to start my windows application or program that is to start each Windows application starts Deutsch: Hallo. Ich möchte mein Windows-Anwendung zu starten oder das Programm zu starten, die jeder Windows-Anwendung ist gestartet
specialforce windows-application error
04/22/2011 - Soldier Front Philippines - 6 Replies
mga kuya anu maiiwasan i2?
C# Windows Form Application How To Save And Run As Application?
02/18/2010 - CO2 Private Server - 4 Replies
How can I save the project and run it as a exe and not .resx or whatever?
C# Windows Form Application Errors
02/17/2010 - CO2 Private Server - 4 Replies
When I open up a new project, even before I do anything I get these errors in Program.cs: Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(fal se); Application.Run(new Form1()); How can I fix these?



All times are GMT +2. The time now is 06:46.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.