0% found this document useful (0 votes)
2 views

Sample Calculator Script

This document contains a C# Windows Forms application for a simple calculator. It includes methods for addition, subtraction, and multiplication, each handling input from two text boxes and displaying the result. Error handling is implemented to alert users when invalid numbers are entered.

Uploaded by

merir143
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Sample Calculator Script

This document contains a C# Windows Forms application for a simple calculator. It includes methods for addition, subtraction, and multiplication, each handling input from two text boxes and displaying the result. Error handling is implemented to alert users when invalid numbers are entered.

Uploaded by

merir143
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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
{
public Form1()
{
InitializeComponent();
}

private void btnAdd_Click(object sender, EventArgs e)


{
try
{
Double Number1 = Convert.ToDouble(txtNum1.Text);
Double Number2 = Convert.ToDouble(txtNum2.Text);
Double Result = Number1 + Number2;
txtResult.Text = Result.ToString();
//MessageBox.Show(" Result of the two Number is " + Result);
}

catch (FormatException)
{
MessageBox.Show("You have to enter a valide number" );
}

private void btnSubtract_Click(object sender, EventArgs e)


{
try
{
Double Number1 = Convert.ToDouble(txtNum1.Text);
Double Number2 = Convert.ToDouble(txtNum2.Text);
//Result = Convert.ToDouble(txtResult.Text);
Double Result = Number1 - Number2;
txtResult.Text = Result.ToString();
//MessageBox.Show(" Result of the two Number is " + Result);
}

catch (FormatException)
{
MessageBox.Show("You have to enter a valide number");
}
}

private void btnmultiplay_Click(object sender, EventArgs e)


{
try
{
Double Number1 = Convert.ToDouble(txtNum1.Text);
Double Number2 = Convert.ToDouble(txtNum2.Text);
//Result = Convert.ToDouble(txtResult.Text);
Double Result = Number1 * Number2;
txtResult.Text = Result.ToString();
//MessageBox.Show(" Result of the two Number is " + Result);
}

catch (FormatException)
{
MessageBox.Show("You have to enter a valide number");
}
}
}
}

You might also like