(Interface of calculator design in C#)
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 Calculator
{
public partial class Form1 : Form
{
Double resultValue = 0;
String operationperformend = "";
bool isoperationperformed=false;
public Form1()
{
InitializeComponent();
}
private void button18_Click(object sender, EventArgs e)
{
if( (textBox1.Text == "0")|| (isoperationperformed))
textBox1.Clear();
isoperationperformed = false;
Button btn = (Button)sender;
if (btn.Text==".")
{
if (!textBox1.Text.Contains("."))
textBox1.Text = textBox1.Text + btn.Text;
}
else
textBox1.Text = textBox1.Text + btn.Text;
}
private void Operations(object sender, EventArgs e)
{
Button btn = (Button)sender;
if (resultValue != 0)
{
button11.PerformClick();
operationperformend = btn.Text;
label1.Text = resultValue + " " + operationperformend;
isoperationperformed = true;
}
else
{
operationperformend = btn.Text;
resultValue = Double.Parse(textBox1.Text);
label1.Text = resultValue + " " + operationperformend;
isoperationperformed = true;
}
}
private void button10_Click(object sender, EventArgs e)
{
switch (operationperformend)
{
case "+":
textBox1.Text = (resultValue + Double.Parse(textBox1.Text)).ToString();
break;
case "-":
textBox1.Text = (resultValue - Double.Parse(textBox1.Text)).ToString();
break;
case "*":
textBox1.Text = (resultValue * Double.Parse(textBox1.Text)).ToString();
break;
case "/":
textBox1.Text = (resultValue / Double.Parse(textBox1.Text)).ToString();
break;
default:
break;
}
resultValue = Double.Parse(textBox1.Text);
label1.Text = "";
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text = "0";
resultValue = 0;
}
private void button5_Click(object sender, EventArgs e)
{
Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Post a Comment
Post a Comment
Please do not enter any spam link in the comment box