Вы находитесь на странице: 1из 9

using System;

using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
namespace calculatorapp
{
class Program:Form
{
decimal n1=0.0m;
string s1;
//Stack st = new Stack();
ArrayList arr = new ArrayList();
Button bt1 = new Button();
Button bt2 = new Button();
Button bt3 = new Button();
Button bt4 = new Button();
Button bt5 = new Button();
Button bt6 = new Button();
Button bt7 = new Button();
Button bt8 = new Button();
Button bt9 = new Button();
Button bt10 = new Button();
Button bt11 = new Button();
Button bt12 = new Button();
Button bt13 = new Button();
Button bt14 = new Button();
Button bt15 = new Button();
Button bt16 = new Button();
Button bt17 = new Button();
static TextBox t1 = new TextBox();

public Program()
{

// textbox setting
t1.Location = new Point(15,10);
t1.Size = new Size(250,20);
this.Controls.Add(t1);
t1.Text = "0";
this.Text = "CALCULATOR 1.0.0";
this.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\tex
1.jpg");
//button1 size and location
bt1.Location = new Point(15,40);
bt1.Size = new Size(30,30);
bt1.Text = "1";
bt1.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
bt1.Font = new Font(bt1.Font, FontStyle.Bold);
this.Controls.Add(bt1);

//button 2 size and location
bt2.Location = new Point(70,40);
bt2.Size = new Size(30,30);
bt2.Text = "2";
bt2.Font = new Font(bt2.Font, FontStyle.Bold);
bt2.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
this.Controls.Add(bt2);

//button3 size and location
bt3.Location = new Point(125, 40);
bt3.Size = new Size(30, 30);
bt3.Text = "3";
bt3.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
bt3.Font = new Font(bt3.Font, FontStyle.Bold);
this.Controls.Add(bt3);

//button4 size and location
bt4.Location = new Point(180, 40);
bt4.Size = new Size(30, 30);
bt4.Text = "4";
bt4.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
bt4.Font = new Font(bt4.Font, FontStyle.Bold);
this.Controls.Add(bt4);

//button5 location and setting
bt5.Location = new Point(15, 80);
bt5.Size = new Size(30, 30);
bt5.Text = "5";
bt5.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
bt5.Font = new Font(bt5.Font, FontStyle.Bold);
this.Controls.Add(bt5);

//button 6 location and settings
bt6.Location = new Point(70, 80);
bt6.Size = new Size(30, 30);
bt6.Text = "6";
bt6.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
bt6.Font = new Font(bt6.Font, FontStyle.Bold);
this.Controls.Add(bt6);

//button7 location and size
bt7.Location = new Point(125, 80);
bt7.Size = new Size(30, 30);
bt7.Text = "7";
bt7.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
bt7.Font = new Font(bt7.Font, FontStyle.Bold);
this.Controls.Add(bt7);

//button8 location and size
bt8.Location = new Point(180, 80);
bt8.Size = new Size(30, 30);
bt8.Text = "8";
bt8.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
bt8.Font = new Font(bt8.Font, FontStyle.Bold);
this.Controls.Add(bt8);

//button9 location and size
bt9.Location = new Point(15, 120);
bt9.Size = new Size(30, 30);
bt9.Text = "9";
bt9.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flow
er.jpg");
bt9.Font = new Font(bt9.Font, FontStyle.Bold);
this.Controls.Add(bt9);

//button10 location and size
bt10.Location = new Point(70, 120);
bt10.Size = new Size(30, 30);
bt10.Text = "+";
bt10.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flo
wer.jpg");
bt10.Font = new Font(bt10.Font, FontStyle.Bold);
this.Controls.Add(bt10);

//button11 location and size
bt11.Location = new Point(125, 120);
bt11.Size = new Size(30, 30);
bt11.Text = "--";
bt11.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flo
wer.jpg");
bt11.Font = new Font(bt11.Font, FontStyle.Bold);
this.Controls.Add(bt11);

//button12 location and size
bt12.Location = new Point(180, 120);
bt12.Size = new Size(30, 30);
bt12.Text = "X";
bt12.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flo
wer.jpg");
bt12.Font = new Font(bt12.Font, FontStyle.Bold);
this.Controls.Add(bt12);

//button13 location and size
bt13.Location = new Point(15, 160);
bt13.Size = new Size(60, 60);
bt13.Text = "Clear";
bt13.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flo
wer.jpg");
bt13.Font = new Font(bt13.Font, FontStyle.Bold);
this.Controls.Add(bt13);
//button14 location and size
bt14.Location = new Point(220, 40);
bt14.Size = new Size(50, 109);
bt14.Text = "==";
bt14.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flo
wer.jpg");
bt14.Font = new Font(bt14.Font, FontStyle.Bold);
this.Controls.Add(bt14);
//button15 location and size
bt15.Location = new Point(80,160);
bt15.Size = new Size(70,60);
bt15.Text = "/";
bt15.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flo
wer.jpg");
bt15.Font = new Font(bt15.Font, FontStyle.Bold);
this.Controls.Add(bt15);
//button16 location and size
bt16.Location = new Point(160, 160);
bt16.Size = new Size(50, 60);
bt16.Text = "0";
bt16.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flo
wer.jpg");
bt16.Font = new Font(bt16.Font, FontStyle.Bold);
this.Controls.Add(bt16);


//button17 location and size
bt17.Location = new Point(220, 160);
bt17.Size = new Size(50, 60);
bt17.Text = ".";
bt17.BackgroundImage = Image.FromFile(@"C:\Users\anumeha\Desktop\flo
wer.jpg");
bt17.Font = new Font(bt17.Font, FontStyle.Bold);
this.Controls.Add(bt17);


//buttonevent handler
bt1.Click += new EventHandler(OnClick1);
bt2.Click += new EventHandler(OnClick2);
bt3.Click += new EventHandler(OnClick3);
bt4.Click += new EventHandler(OnClick4);
bt5.Click += new EventHandler(OnClick5);
bt6.Click += new EventHandler(OnClick6);
bt7.Click += new EventHandler(OnClick7);
bt8.Click += new EventHandler(OnClick8);
bt9.Click += new EventHandler(OnClick9);
bt10.Click += new EventHandler(OnClick10);
bt11.Click += new EventHandler(OnClick11);
bt12.Click += new EventHandler(OnClick12);
bt13.Click += new EventHandler(OnClick13);
bt14.Click += new EventHandler(OnClick14);
bt15.Click += new EventHandler(OnClick15);
bt16.Click += new EventHandler(OnClick16);
bt17.Click += new EventHandler(OnClick17);

}
//functionality of button16
public void OnClick16(object sender, EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "0";
}
else
t1.Text = "0";
}
//functionality of button1
public void OnClick1(object sender,EventArgs ee )
{
if (t1.Text != "")
{
t1.Text = t1.Text + "1";
}
else
t1.Text = "1";
}

//functionality of button2
public void OnClick2(object sender, EventArgs e)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "2";
}
else
t1.Text = "2";
}


//functionality of button3
public void OnClick3(object sender, EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "3";
}
else
t1.Text = "3";
}
//functionality of button4
public void OnClick4(object sender, EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "4";
}
else
t1.Text = "4";
}
//functionality of button5
public void OnClick5(object sender, EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "5";
}
else
t1.Text = "5";
}
//functionality of button6
public void OnClick6(object sender, EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "6";
}
else
t1.Text = "6";
}
//functionality of button7
public void OnClick7(object sender, EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "7";
}
else
t1.Text = "7";
}
//functionality of button8
public void OnClick8(object sender, EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "8";
}
else
t1.Text = "8";
}
//functionality of button9
public void OnClick9(object sender, EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + "2";
}
else
t1.Text = "9";
}
//functionality of button10 that is button of addition
public void OnClick10(object sender, EventArgs ee)
{
arr.Add(t1.Text);
t1.Text = "";
string s2=null;
if (arr.Count > 1)
{

n1 =(Convert.ToDecimal(arr[0]) + Convert.ToDecimal(arr[1]));
s2 = n1.ToString("00.00000");
t1.Text = n1.ToString("00.00000");

arr.Clear();
}
s1 = "+";

}
//functionality of button11 that is button of substraction
public void OnClick11(object sender,EventArgs ee)
{
arr.Add(t1.Text);
t1.Text = "";
if (arr.Count > 1)
{
n1 = Convert.ToDecimal(arr[0]) - Convert.ToDecimal(arr[1]);
t1.Text = n1.ToString();

arr.Clear();
}
s1 = "-";
}



//button 12 shows functionality of multiplication
public void OnClick12(object sender, EventArgs ee)
{
arr.Add(t1.Text);
t1.Text = "";
if (arr.Count > 1)
{
n1 = Convert.ToDecimal(arr[0]) * Convert.ToDecimal(arr[1]);
t1.Text = n1.ToString();

arr.Clear();
}
s1 = "*";
}


//functionality of button13 that is of clear text
public static void OnClick13(object sender, EventArgs ee)
{
t1.Text = "";
}
//functionality of button14 that is equals
public void OnClick14(object sender ,EventArgs ee)
{
//t1.Text = t2.Text;
if (s1 == "+")
{
arr.Add(t1.Text);
t1.Text = "";
string s2 = null;
if (arr.Count > 1)
{
n1 = Convert.ToDecimal(arr[0]) + Convert.ToDecimal(arr[1]);
s2 = n1.ToString();
t1.Text = n1.ToString();
arr.Clear();
}
// s1 = "+";

}
else if (s1 == "-")
{
arr.Add(t1.Text);
t1.Text = "";
string s2 = null;
if (arr.Count > 1)
{
n1 = Convert.ToDecimal(arr[0]) - Convert.ToDecimal(arr[1]);
s2 = n1.ToString();
t1.Text = n1.ToString();
arr.Clear();
}


}
else if(s1=="*")
{
arr.Add(t1.Text);
t1.Text = "";
string s2 = null;
if (arr.Count > 1)
{
n1 = Convert.ToDecimal(arr[0]) * Convert.ToDecimal(arr[1]);
s2 = n1.ToString();
t1.Text = n1.ToString();
arr.Clear();
}

}
else if (s1 == "/")
{
arr.Add(t1.Text);
t1.Text = "";
string s2 = null;
if (arr.Count > 1)
{
n1 = Convert.ToDecimal(arr[0]) / Convert.ToDecimal(arr[1]);
s2 = n1.ToString();
t1.Text = n1.ToString();
arr.Clear();
}
}
}
public void OnClick17(object sender,EventArgs ee)
{
if (t1.Text != "")
{
t1.Text = t1.Text + ".";
}
else
t1.Text = ".";
}



public void OnClick15(object sender, EventArgs ee)
{
arr.Add(t1.Text);
t1.Text = "";
if (arr.Count > 1)
{
n1 = Convert.ToDecimal(arr[0]) / Convert.ToDecimal(arr[1]);
t1.Text = n1.ToString("00.00000");
arr.Clear();
}
s1 = "/";
}

static void Main(string[] args)
{

Program p = new Program();
Application.Run(new Program());
}
}
}

Вам также может понравиться