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

C# 11

The document describes creating a Windows forms application for a simple calculator. It includes code to handle button clicks for numbers, operators, and functions like clear and equals. The code uses a string to store the calculation and updates labels to display the current expression and result.

Uploaded by

Aditya Konnur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

C# 11

The document describes creating a Windows forms application for a simple calculator. It includes code to handle button clicks for numbers, operators, and functions like clear and equals. The code uses a string to store the calculation and updates labels to display the current expression and result.

Uploaded by

Aditya Konnur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Experiment No.

11

1. Design & Develop windows application for simple Calculator

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;
using static System.Net.Mime.MediaTypeNames;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace EXP11
{
public partial class Form1 : Form
{
string rs="";

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{

rs = label2.Text;
DataTable dt = new DataTable();
try
{
Experiment No. 11

var v = dt.Compute(rs, "");


label1.Text = v.ToString();
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
}

private void button2_Click(object sender, EventArgs e)


{
rs+=("1");
label2.Text = rs;
}

private void button3_Click(object sender, EventArgs e)


{
rs+="2";
label2.Text = rs.ToString();
}

private void button4_Click(object sender, EventArgs e)


{
rs+="3";
label2.Text = rs.ToString();
}

private void button13_Click(object sender, EventArgs e)


{
rs+="4";
label2.Text = rs.ToString();
}
Experiment No. 11

private void button12_Click(object sender, EventArgs e)


{
rs+="5";
label2.Text = rs.ToString();
}

private void button11_Click(object sender, EventArgs e)


{
rs+="6";
label2.Text = rs.ToString();
}

private void button17_Click(object sender, EventArgs e)


{
rs+="7";
label2.Text = rs.ToString();
}

private void button16_Click(object sender, EventArgs e)


{
rs+="8";
label2.Text = rs.ToString();
}

private void button15_Click(object sender, EventArgs e)


{
rs+="9";
label2.Text = rs.ToString();
}

private void button21_Click(object sender, EventArgs e)


Experiment No. 11

{
rs+="00";
label2.Text = rs.ToString();
}

private void button20_Click(object sender, EventArgs e)


{
rs+="0";
label2.Text = rs.ToString();
}

private void button19_Click(object sender, EventArgs e)


{
rs+=".";
label2.Text = rs.ToString();
}

private void button14_Click(object sender, EventArgs e)


{
try
{
int a = rs.Length - 1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' &&
rs[a] != '/')
{
rs +="+";
label2.Text = rs.ToString();
}
}catch (Exception ex) { }
}

private void button10_Click(object sender, EventArgs e)


Experiment No. 11

{
try
{
int a = rs.Length - 1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' &&
rs[a] != '/')
{
rs += "-";
label2.Text = rs.ToString();
}
}
catch (Exception ex) { }
}

private void button5_Click(object sender, EventArgs e)


{
try
{
int a = rs.Length - 1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' &&
rs[a] != '/')
{
rs += "*";
label2.Text = rs.ToString();
}
}
catch (Exception ex) { }
}

private void button6_Click(object sender, EventArgs e)


{
try
{
Experiment No. 11

int a = rs.Length - 1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' &&
rs[a] != '/')
{
rs += "/";
label2.Text = rs.ToString();
}
}
catch (Exception ex) { }
}

private void button8_Click(object sender, EventArgs e)


{
try
{
int a=rs.Length-1;
if (rs.Length != 0 && rs[a] != '%' && rs[a] != '+' && rs[a] != '-' && rs[a] != '*' &&
rs[a] != '/')
{
rs += "%";
label2.Text = rs.ToString();
}

}
catch (Exception ex) { }
}

private void button9_Click(object sender, EventArgs e)


{
rs = "";
label2.Text = rs;
label1.Text = rs;
}
Experiment No. 11

private void button7_Click(object sender, EventArgs e)


{
int a = rs.Length - 1;
rs=rs.Remove(a);
label2.Text = rs;
}

private void button18_Click(object sender, EventArgs e)


{
rs = label2.Text;
DataTable dt = new DataTable();
try
{
var v = dt.Compute(rs, "");
label1.Text = v.ToString();
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
}
}
}
Experiment No. 11

You might also like