using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Calculator
{
public class Program:Form
{
private TextBox t1;
private Label lb;
private Button b;
private Button b1;
private Button b2;
private Button b3;
private Button b4;
private Button b5;
private Button b6;
private Button b7;
private Button b8;
private Button b9;
private Button b10;
private Button Add;
private Button Sub;
private Button Mul;
private Button Div;
private Button cham;
private Button ca;
private Button soam;
private Button bp;
private Button gt;
private bool kiemtra;
private string oper, sonho;
private Double n;
private Double s;
private Double i;
MainMenu mMenu;
MenuItem mFile;
MenuItem mExit;
MenuItem mAbout;
public static void Main(string[] args)
{
Application.Run(new Program());
}
public Program()
{
//Design
mMenu = new MainMenu();
mFile=new MenuItem();
mFile.Text="File";
mExit = new MenuItem();
mAbout = new MenuItem();
mAbout.Text = "About";
mAbout.Click += new EventHandler(mAbout_Click);
mExit.Text = "Exit";
mExit = new MenuItem("Exit", new EventHandler(mExit_Click), Shortcut.CtrlE );
mExit.Click+=new EventHandler(mExit_Click);
mFile.MenuItems.Add(mExit);
mMenu.MenuItems.Add(mFile);
mFile.MenuItems.Add(mAbout);
this.Menu = mMenu;
this.Name = "Program";
this.Text = "Tính";
this.Size = new Size(165,280);
this.Load += new EventHandler(Program_Load);
this.FormBorderStyle = FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.lb = new Label();
this.b = new Button();
this.b1 = new Button();
this.b2 = new Button();
this.b3 = new Button();
this.b4 = new Button();
this.b5 = new Button();
this.b6 = new Button();
this.b7 = new Button();
this.b8 = new Button();
this.b9 = new Button();
this.b10 = new Button();
this.Add = new Button();
this.Sub = new Button();
this.Mul = new Button();
this.Div = new Button();
this.cham = new Button();
this.ca = new Button();
this.soam = new Button();
this.bp = new Button();
this.gt = new Button();
this.t1 = new TextBox();
lb.Text = "Tam Calculator@";
b.Text = "=";
b10.Text = "0";
b1.Text = "1";
b2.Text = "2";
b3.Text = "3";
b4.Text = "4";
b5.Text = "5";
b6.Text = "6";
b7.Text = "7";
b8.Text = "8";
b9.Text = "9";
cham.Text = ".";
Add.Text = "+";
Sub.Text = "-";
Mul.Text = "x";
Div.Text = "/";
ca.Text = "CA";
soam.Text = "M-";
bp.Text = "x^2";
gt.Text = "!";
lb.Location=new Point(30,50);
b.Location = new Point(80, 200);
b.Size = new Size(30, 25);
b.Click += new EventHandler(b_Click);
b10.Location = new Point(10,200);
b10.Size = new Size(30, 25);
b10.Click += new EventHandler(b10_Click);
cham.Location = new Point(45, 200);
cham.Size = new Size(30, 25);
cham.Click += new EventHandler(cham_Click);
Add.Location = new Point(115,200);
Add.Size = new Size(30, 25);
Add.Click += new EventHandler(Add_Click);
b1.Location = new Point(10,170);
b1.Click += new EventHandler(b1_Click);
b1.Size = new Size(30, 25);
b2.Location = new Point(45, 170);
b2.Size = new Size(30, 25);
b2.Click += new EventHandler(b2_Click);
b3.Location = new Point(80, 170);
b3.Size = new Size(30, 25);
b3.Click += new EventHandler(b3_Click);
Sub.Location = new Point(115, 170);
Sub.Size = new Size(30, 25);
Sub.Click += new EventHandler(Sub_Click);
b4.Location = new Point(10, 140);
b4.Size = new Size(30, 25);
b4.Click += new EventHandler(b4_Click);
b5.Location = new Point(45, 140);
b5.Size = new Size(30, 25);
b5.Click+=new EventHandler(b5_Click);
b6.Location = new Point(80, 140);
b6.Size = new Size(30, 25);
b6.Click += new EventHandler(b6_Click);
Mul.Location = new Point(115, 140);
Mul.Size = new Size(30, 25);
Mul.Click += new EventHandler(Mul_Click);
b7.Location = new Point(10, 110);
b7.Size = new Size(30, 25);
b7.Click += new EventHandler(b7_Click);
b8.Location = new Point(45, 110);
b8.Size = new Size(30, 25);
b8.Click += new EventHandler(b8_Click);
b9.Location = new Point(80, 110);
b9.Size = new Size(30, 25);
b9.Click += new EventHandler(b9_Click);
Div.Location = new Point(115, 110);
Div.Size = new Size(30, 25);
Div.Click += new EventHandler(Div_Click);
ca.Location = new Point(115, 80);
ca.Size = new Size(30, 25);
ca.Click += new EventHandler(ca_Click);
soam.Location = new Point(80,80);
soam.Size = new Size(30, 25);
soam.Click += new EventHandler(soam_Click);
bp.Location = new Point(45,80);
bp.Size = new Size(30, 25);
bp.Click += new EventHandler(bp_Click);
gt.Location = new Point(10,80);
gt.Size = new Size(30,25);
gt.Click += new EventHandler(gt_Click);
t1.Location = new Point(10, 20);
t1.Size = new Size(135,50);
//Add len Form
this.Controls.Add(lb);
this.Controls.Add(t1);
this.Controls.Add(b);
this.Controls.Add(b10);
this.Controls.Add(b1);
this.Controls.Add(b2);
this.Controls.Add(b3);
this.Controls.Add(b4);
this.Controls.Add(b5);
this.Controls.Add(b6);
this.Controls.Add(b7);
this.Controls.Add(b8);
this.Controls.Add(b9);
this.Controls.Add(Add);
this.Controls.Add(Sub);
this.Controls.Add(Mul);
this.Controls.Add(Div);
this.Controls.Add(cham);
this.Controls.Add(ca);
this.Controls.Add(soam);
this.Controls.Add(bp);
this.Controls.Add(gt);
[You must be registered and logged in to see this link.] }
void mAbout_Click(object sender, EventArgs e)
{
MessageBox.Show("Phần mềm được phát triển bởi Programing Mai Thanh Tâm\nMọi chi tiết xin liên hệ:\n - SĐT: 01688521617\n - Mail:
[You must be registered and logged in to see this link.]", "About", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
}
void gt_Click(object sender, EventArgs e)
{
this.sonho = this.t1.Text;
this.kiemtra = true;
this.oper = "!";
}
void bp_Click(object sender, EventArgs e)
{
this.sonho = this.t1.Text;
this.kiemtra = true;
this.oper = "x^2";
}
void soam_Click(object sender, EventArgs e)
{
this.t1.Text = "-" + this.t1.Text;
}
void ca_Click(object sender, EventArgs e)
{
this.t1.Text = "0.";
this.kiemtra = true;
}
void Program_Load(object sender, EventArgs e)
{
this.t1.Visible = true;
}
void Div_Click(object sender, EventArgs e)
{
this.sonho = this.t1.Text;
this.kiemtra = true;
this.oper = "/";
}
void Mul_Click(object sender, EventArgs e)
{
this.sonho = this.t1.Text;
this.kiemtra = true;
this.oper = "x";
}
void Sub_Click(object sender, EventArgs e)
{
this.sonho = this.t1.Text;
this.kiemtra = true;
this.oper = "-";
}
void Add_Click(object sender, EventArgs e)
{
this.sonho = this.t1.Text;
this.kiemtra = true;
this.oper = "+";
}
void cham_Click(object sender, EventArgs e)
{
if (this.t1.Text.Contains(".")) return;
this.t1.Text = this.t1.Text + ".";
}
void b9_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b9.Text;
this.kiemtra = false;
}
void b8_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b8.Text;
this.kiemtra = false;
}
void b7_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b7.Text;
this.kiemtra = false;
}
void b6_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b6.Text;
this.kiemtra = false;
}
void b5_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b5.Text;
this.kiemtra = false;
}
void b4_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b4.Text;
this.kiemtra = false;
}
void b3_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b3.Text;
this.kiemtra = false;
}
void b2_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b2.Text;
this.kiemtra = false;
}
void b1_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b1.Text;
this.kiemtra = false;
}
public void b10_Click(object sender, EventArgs e)
{
if (kiemtra) this.t1.Clear();
this.t1.Text = this.t1.Text + this.b10.Text;
this.kiemtra = false;
}
public void mExit_Click(Object sender, EventArgs ea)
{
Application.Exit();
}
public void miFileOpen_Click(Object sender, EventArgs ea)
{
MessageBox.Show("Menu Open Click");
}
public void b_Click(object sender, EventArgs e)
{
double b = Convert.ToDouble(this.t1.Text);
double a = Convert.ToDouble(this.sonho);
if (this.oper == "+")
{
this.t1.Text = Convert.ToString(a + b);
}
if (this.oper == "-")
{
this.t1.Text = Convert.ToString(a - b);
}
if (this.oper == "x")
{
this.t1.Text = Convert.ToString(a * b);
}
if (this.oper == "/")
{
this.t1.Text = Convert.ToString(a / b);
}
if (this.oper == "x^2")
{
this.t1.Text = Convert.ToString(a * a);
}
if (this.oper == "!")
{
s = 1;
n = a; ;
for (i = 1; i < n; i++)
{
s = s * i;
}
this.t1.Text = Convert.ToString(s*i);
}
this.kiemtra = true ;
}
}
}