Vous êtes sur la page 1sur 9

using System;

using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Galay_And_Peñaflorida
{

public partial class MainForm : Form


{
public MainForm()
{

InitializeComponent();

double num1, num2, ans;


string op = string.Empty;

void MainFormLoad(object sender, EventArgs e)


{
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
btn6.Enabled = false;
btn7.Enabled = false;
btn8.Enabled = false;
btn9.Enabled = false;
btnNum0.Enabled = false;
btnPlus.Enabled = false;
btnMinus.Enabled = false;
btnMultiply.Enabled = false;
btnDivide.Enabled = false;
btnDecimal.Enabled = false;
btnClear.Enabled = false;
btnEquals.Enabled = false;
}
void BtnSwitchClick(object sender, EventArgs e)
{

if (btnSwitch.Text == "OFF") {
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
btn6.Enabled = false;
btn7.Enabled = false;
btn8.Enabled = false;
btn9.Enabled = false;
btnNum0.Enabled = false;
btnPlus.Enabled = false;
btnMinus.Enabled = false;
btnMultiply.Enabled = false;
btnDivide.Enabled = false;
btnDecimal.Enabled = false;
btnClear.Enabled = false;
btnEquals.Enabled = false;
btnSwitch.Text = "ON";
lblOutput.Text = string.Empty;
lblOutput.Enabled = false;
}
else if (btnSwitch.Text == "ON") {
btn1.Enabled = true;
btn2.Enabled = true;
btn3.Enabled = true;
btn4.Enabled = true;
btn5.Enabled = true;
btn6.Enabled = true;
btn7.Enabled = true;
btn8.Enabled = true;
btn9.Enabled = true;
btnNum0.Enabled = true;
btnPlus.Enabled = true;
btnMinus.Enabled = true;
btnMultiply.Enabled = true;
btnDivide.Enabled = true;
btnDecimal.Enabled = true;
btnClear.Enabled = true;
btnEquals.Enabled = true;
btnSwitch.Text = "OFF";
lblOutput.Enabled = true;
}
}
void BtnNum0Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "0";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "0";
}
}
void Btn1Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "1";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "1";
}
}
void Btn2Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "2";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "2";
}
}
void Btn3Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "3";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "3";
}
}
void Btn4Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "4";
}
else if (lblOutput.Text != string.Empty) {
if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "4";
}
}
void Btn5Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "5";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "5";
}
}
void Btn6Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "6";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {
lblOutput.Text= "";
}

lblOutput.Text += "6";
}
}
void Btn7Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "7";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "7";
}
}
void Btn8Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "8";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "8";
}
}
void Btn9Click(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty) {
lblOutput.Text += "9";
}
else if (lblOutput.Text != string.Empty) {

if (lblOutput.Text == "+" ||
lblOutput.Text == "-" ||
lblOutput.Text == "*" ||
lblOutput.Text == "/") {

lblOutput.Text= "";
}

lblOutput.Text += "9";
}
}
void BtnDecimalClick(object sender, EventArgs e)
{
if (lblOutput.Text == string.Empty && lblOutput.Text != string.Empty) {
lblOutput.Text = ".";
}
else
{
lblOutput.Text = lblOutput.Text + ".";
}
}
void BtnClearClick(object sender, EventArgs e)
{
lblOutput.Text = string.Empty;
}
void BtnPlusClick(object sender, EventArgs e)
{
num1 = Convert.ToDouble(lblOutput.Text);
lblOutput.Text = "+";
op = "+";
}
void BtnMinusClick(object sender, EventArgs e)
{
num1 = Convert.ToDouble(lblOutput.Text);
lblOutput.Text = "-";
op = "-";
}
void BtnMultiplyClick(object sender, EventArgs e)
{
num1 = Convert.ToDouble(lblOutput.Text);
lblOutput.Text = "*";
op = "*";
}
void BtnDivideClick(object sender, EventArgs e)
{
num1 = Convert.ToDouble(lblOutput.Text);
lblOutput.Text = "/";
op = "/";
}
void BtnEqualsClick(object sender, EventArgs e)
{
num2 = Convert.ToDouble(lblOutput.Text);

switch (op) {
case "+":

ans = (num1 + num2);


lblOutput.Text = Convert.ToString(ans);
break;

case "-":

ans = (num1 - num2);

lblOutput.Text = Convert.ToString(ans);
break;

case "*":

ans = (num1 * num2);

lblOutput.Text = Convert.ToString(ans);
break;

case "/":

ans = num1 / num2;


lblOutput.Text = Convert.ToString(ans);
break;

}
}

Vous aimerez peut-être aussi