[C#] Simple Calculator Source

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
Dec 19, 2014
517
380
133
Crunch
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 WindowsFormsApplication2_Login_
{
  public partial class Calculator : Form
  {
  public Calculator()
  {
  InitializeComponent();
  }

  public void disable()
  {
  button13.Hide();
  button1.Show();
  button20.Enabled = false;
  button19.Enabled = false;
  button18.Enabled = false;
  button17.Enabled = false;
  button16.Enabled = false;
  button15.Enabled = false;
  button14.Enabled = false;
  button13.Enabled = false;
  button12.Enabled = false;
  button11.Enabled = false;
  button10.Enabled = false;
  button9.Enabled = false;
  button8.Enabled = false;
  button7.Enabled = false;
  button6.Enabled = false;
  button5.Enabled = false;
  button4.Enabled = false;
  button3.Enabled = false;
  button2.Enabled = false;
  }

  public void enable()
  {
  button1.Hide();
  button13.Show();
  button20.Enabled = true;
  button19.Enabled = true;
  button18.Enabled = true;
  button17.Enabled = true;
  button16.Enabled = true;
  button15.Enabled = true;
  button14.Enabled = true;
  button12.Enabled = true;
  button11.Enabled = true;
  button10.Enabled = true;
  button9.Enabled = true;
  button8.Enabled = true;
  button7.Enabled = true;
  button6.Enabled = true;
  button5.Enabled = true;
  button4.Enabled = true;
  button2.Enabled = true;
  }

  float num, ans;
  int count;

  public void compute()
  {
  switch(count)
  {
  case 1:
  ans = num + float.Parse(textBox1.Text);
  textBox1.Text = ans.ToString();
  break;

  case 2:
  ans = num - float.Parse(textBox1.Text);
  textBox1.Text = ans.ToString();
  break;

  case 3:
  ans = num / float.Parse(textBox1.Text);
  textBox1.Text = ans.ToString();
  break;

  case 4:
  ans = num * float.Parse(textBox1.Text);
  textBox1.Text = ans.ToString();
  break;

  }
  }

  private void button17_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 0;
  textBox1.ForeColor = Color.Red;
  }

  private void button18_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + ".";
  textBox1.ForeColor = Color.Red;
  }

  private void button14_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 1;
  textBox1.ForeColor = Color.Red;
  }

  private void button15_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 2;
  textBox1.ForeColor = Color.Red;
  }

  private void button16_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 3;
  textBox1.ForeColor = Color.Red;
  }

  private void button9_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 4;
  textBox1.ForeColor = Color.Red;
  }

  private void button10_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 5;
  textBox1.ForeColor = Color.Red;
  }

  private void button11_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 6;
  textBox1.ForeColor = Color.Red;
  }

  private void button5_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 7;
  textBox1.ForeColor = Color.Red;
  }

  private void button6_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 8;
  textBox1.ForeColor = Color.Red;
  }

  private void button7_Click(object sender, EventArgs e)
  {
  textBox1.Text = textBox1.Text + 9;
  textBox1.ForeColor = Color.Red;
  }

  private void button1_Click(object sender, EventArgs e)//On Button
  {
  enable();
  }

  private void button13_Click(object sender, EventArgs e)//Off Button
  {
  disable();
  }

  private void button4_Click(object sender, EventArgs e)
  {
  num = float.Parse(textBox1.Text);
  textBox1.Clear();
  textBox1.Focus();
  count = 1;
  label1.Text = num.ToString() + "+";
  }

  private void button8_Click(object sender, EventArgs e)
  {
  num = float.Parse(textBox1.Text);
  textBox1.Clear();
  textBox1.Focus();
  count = 1;
  label1.Text = num.ToString() + "-";
  }

  private void button3_Click(object sender, EventArgs e)
  {
  num = float.Parse(textBox1.Text);
  textBox1.Clear();
  textBox1.Focus();
  count = 1;
  label1.Text = num.ToString() + "*";
  }

  private void button12_Click(object sender, EventArgs e)
  {
  num = float.Parse(textBox1.Text);
  textBox1.Clear();
  textBox1.Focus();
  count = 1;
  label1.Text = num.ToString() + "/";
  }

  private void button19_Click(object sender, EventArgs e)
  {
  compute();
  label1.Text = "";
  }

  private void button20_Click(object sender, EventArgs e)
  {
  textBox1.Text = "";
  }

  private void button2_Click(object sender, EventArgs e)
  {
  int lenght = textBox1.TextLength - 1;
  string text = textBox1.Text;
  textBox1.Clear();
  for (int i = 0; i < lenght; i++)
  textBox1.Text = textBox1.Text + text[i];
  }
  }
}
 
  • Like
Reactions: Younis
General chit-chat
Help Users
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Manuel1233457 is our newest member. Welcome!
  • Chat Bot:
    TY2XYT has left the room.
  • @ QM|T_JinX:
    l..........................[]
  • Chat Bot:
    Rom_c is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • @ Spirit:
    Merry Christmas all :)
  • @ Luke:
    Merry Christmas you filthy animals
  • @ Dana White:
    Merry Christmas
  • Chat Bot:
    mirza_ba is our newest member. Welcome!
  • Chat Bot:
    MATTZK is our newest member. Welcome!
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    polhaasje13 is our newest member. Welcome!
  • Chat Bot:
    polhaasje13 has posted a new reply in the thread "The Last of Us Hack".
  • Chat Bot:
    polhaasje13 has posted a new reply in the thread "The Last of Us Hack".
  • Chat Bot:
    polhaasje13 has posted a new reply in the thread "MOD MENU COLLECTION V1 PKG".
  • Chat Bot:
    socolivein is our newest member. Welcome!
  • Chat Bot:
    Marley vizard is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
      Chat Bot: QM|T_JinX has joined the room.