• 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.

[C#] Simple Calculator Source

Elite_Modz

Active Poster
Retired Staff
Active Member
Console ID Poster
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];
  }
  }
}
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    Omar-_- is our newest member. Welcome!
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    lilmonster3 is our newest member. Welcome!
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    765rdchy5rfvbj5edcvj4ed is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    wilson sales is our newest member. Welcome!
  • Chat Bot:
    riggv is our newest member. Welcome!
  • Chat Bot:
    ripthors is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    modmonkey is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    ZynxDEX is our newest member. Welcome!
  • Chat Bot:
    ZynxDEX has started a new thread called "Console ID" in Console ID's.
      Chat Bot: ZynxDEX has started a new thread called "Console ID" in Console ID's.
      Back
      Top