您的位置:首页 > 编程语言 > C#

Visual C# .Net 计算器部分代码

2007-04-11 16:31 134 查看
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 我的计算器
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Button button11;
private System.Windows.Forms.Button button12;
private System.Windows.Forms.Button button13;
private System.Windows.Forms.Button button14;
private System.Windows.Forms.Button button15;
private System.Windows.Forms.Button button16;
private System.Windows.Forms.Button button17;
private System.Windows.Forms.Button button18;
private System.Windows.Forms.Button button19;
private System.Windows.Forms.Button button20;
private System.Windows.Forms.Button button21;
private System.Windows.Forms.Button button22;
private System.Windows.Forms.Button button23;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button24;
private System.Windows.Forms.Button button25;
private System.Windows.Forms.Button button26;
private System.Windows.Forms.Button button27;
public double cjs1=0,cjs2=0;
public string fh="",fh2="",fh3="";
public double ccs=0;
private System.Windows.Forms.Button button28;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.button11 = new System.Windows.Forms.Button();
this.button12 = new System.Windows.Forms.Button();
this.button13 = new System.Windows.Forms.Button();
this.button14 = new System.Windows.Forms.Button();
this.button15 = new System.Windows.Forms.Button();
this.button16 = new System.Windows.Forms.Button();
this.button17 = new System.Windows.Forms.Button();
this.button18 = new System.Windows.Forms.Button();
this.button19 = new System.Windows.Forms.Button();
this.button20 = new System.Windows.Forms.Button();
this.button21 = new System.Windows.Forms.Button();
this.button22 = new System.Windows.Forms.Button();
this.button23 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button24 = new System.Windows.Forms.Button();
this.button25 = new System.Windows.Forms.Button();
this.button26 = new System.Windows.Forms.Button();
this.button27 = new System.Windows.Forms.Button();
this.button28 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2,
this.menuItem3});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem4,
this.menuItem5});
this.menuItem1.Text = "编辑(&E)";
//
// menuItem4
//
this.menuItem4.Index = 0;
this.menuItem4.Text = "复制(&C)";
//
// menuItem5
//
this.menuItem5.Index = 1;
this.menuItem5.Text = "粘贴(&V)";
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem6,
this.menuItem7,
this.menuItem8,
this.menuItem9});
this.menuItem2.Text = "查看(&V)";
//
// menuItem6
//
this.menuItem6.Checked = true;
this.menuItem6.Index = 0;
this.menuItem6.Text = "标准型(&T)";
//
// menuItem7
//
this.menuItem7.Index = 1;
this.menuItem7.Text = "科学型(&S)";
//
// menuItem8
//
this.menuItem8.Index = 2;
this.menuItem8.Text = "-";
//
// menuItem9
//
this.menuItem9.Index = 3;
this.menuItem9.Text = "数字分组(&I)";
//
// menuItem3
//
this.menuItem3.Index = 2;
this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem10,
this.menuItem11,
this.menuItem12});
this.menuItem3.Text = "帮助(&H)";
//
// menuItem10
//
this.menuItem10.Index = 0;
this.menuItem10.Text = "帮助主题(&H)";
//
// menuItem11
//
this.menuItem11.Index = 1;
this.menuItem11.Text = "-";
//
// menuItem12
//
this.menuItem12.Index = 2;
this.menuItem12.Text = "关于计算器(&A)";
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.Color.White;
this.textBox1.Location = new System.Drawing.Point(8, 0);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(288, 23);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// button1
//
this.button1.ForeColor = System.Drawing.Color.Blue;
this.button1.Location = new System.Drawing.Point(64, 160);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(40, 30);
this.button1.TabIndex = 1;
this.button1.Text = "1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.ForeColor = System.Drawing.Color.Blue;
this.button2.Location = new System.Drawing.Point(112, 160);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(40, 30);
this.button2.TabIndex = 2;
this.button2.Text = "2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.ForeColor = System.Drawing.Color.Blue;
this.button3.Location = new System.Drawing.Point(160, 160);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(40, 30);
this.button3.TabIndex = 3;
this.button3.Text = "3";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.ForeColor = System.Drawing.Color.Blue;
this.button4.Location = new System.Drawing.Point(64, 120);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(40, 30);
this.button4.TabIndex = 4;
this.button4.Text = "4";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.ForeColor = System.Drawing.Color.Blue;
this.button5.Location = new System.Drawing.Point(112, 120);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(40, 30);
this.button5.TabIndex = 5;
this.button5.Text = "5";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.ForeColor = System.Drawing.Color.Blue;
this.button6.Location = new System.Drawing.Point(160, 120);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(40, 30);
this.button6.TabIndex = 6;
this.button6.Text = "6";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.ForeColor = System.Drawing.Color.Blue;
this.button7.Location = new System.Drawing.Point(64, 80);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(40, 30);
this.button7.TabIndex = 7;
this.button7.Text = "7";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button8
//
this.button8.ForeColor = System.Drawing.Color.Blue;
this.button8.Location = new System.Drawing.Point(112, 80);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(40, 30);
this.button8.TabIndex = 8;
this.button8.Text = "8";
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// button9
//
this.button9.ForeColor = System.Drawing.Color.Blue;
this.button9.Location = new System.Drawing.Point(160, 80);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(40, 30);
this.button9.TabIndex = 9;
this.button9.Text = "9";
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// button10
//
this.button10.ForeColor = System.Drawing.Color.Blue;
this.button10.Location = new System.Drawing.Point(64, 200);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(40, 30);
this.button10.TabIndex = 10;
this.button10.Text = "0";
this.button10.Click += new System.EventHandler(this.button10_Click);
//
// button11
//
this.button11.ForeColor = System.Drawing.Color.Red;
this.button11.Location = new System.Drawing.Point(8, 80);
this.button11.Name = "button11";
this.button11.Size = new System.Drawing.Size(40, 30);
this.button11.TabIndex = 11;
this.button11.Text = "MC";
this.button11.Click += new System.EventHandler(this.button11_Click);
//
// button12
//
this.button12.ForeColor = System.Drawing.Color.Red;
this.button12.Location = new System.Drawing.Point(8, 120);
this.button12.Name = "button12";
this.button12.Size = new System.Drawing.Size(40, 30);
this.button12.TabIndex = 12;
this.button12.Text = "MR";
this.button12.Click += new System.EventHandler(this.button12_Click);
//
// button13
//
this.button13.ForeColor = System.Drawing.Color.Red;
this.button13.Location = new System.Drawing.Point(8, 160);
this.button13.Name = "button13";
this.button13.Size = new System.Drawing.Size(40, 30);
this.button13.TabIndex = 13;
this.button13.Text = "MS";
this.button13.Click += new System.EventHandler(this.button13_Click);
//
// button14
//
this.button14.ForeColor = System.Drawing.Color.Red;
this.button14.Location = new System.Drawing.Point(8, 200);
this.button14.Name = "button14";
this.button14.Size = new System.Drawing.Size(40, 30);
this.button14.TabIndex = 14;
this.button14.Text = "M+";
this.button14.Click += new System.EventHandler(this.button14_Click);
//
// button15
//
this.button15.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button15.ForeColor = System.Drawing.Color.Red;
this.button15.Location = new System.Drawing.Point(64, 40);
this.button15.Name = "button15";
this.button15.Size = new System.Drawing.Size(72, 30);
this.button15.TabIndex = 15;
this.button15.Text = "Backspace";
this.button15.Click += new System.EventHandler(this.button15_Click);
//
// button16
//
this.button16.Font = new System.Drawing.Font("宋体", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button16.ForeColor = System.Drawing.Color.Red;
this.button16.Location = new System.Drawing.Point(208, 80);
this.button16.Name = "button16";
this.button16.Size = new System.Drawing.Size(40, 30);
this.button16.TabIndex = 16;
this.button16.Text = "/";
this.button16.Click += new System.EventHandler(this.button16_Click);
//
// button17
//
this.button17.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button17.ForeColor = System.Drawing.Color.Blue;
this.button17.Location = new System.Drawing.Point(256, 80);
this.button17.Name = "button17";
this.button17.Size = new System.Drawing.Size(40, 30);
this.button17.TabIndex = 17;
this.button17.Text = "sqrt";
this.button17.Click += new System.EventHandler(this.button17_Click);
//
// button18
//
this.button18.ForeColor = System.Drawing.Color.Red;
this.button18.Location = new System.Drawing.Point(208, 120);
this.button18.Name = "button18";
this.button18.Size = new System.Drawing.Size(40, 30);
this.button18.TabIndex = 18;
this.button18.Text = "*";
this.button18.Click += new System.EventHandler(this.button18_Click);
//
// button19
//
this.button19.ForeColor = System.Drawing.Color.Blue;
this.button19.Location = new System.Drawing.Point(256, 120);
this.button19.Name = "button19";
this.button19.Size = new System.Drawing.Size(40, 30);
this.button19.TabIndex = 19;
this.button19.Text = "%";
this.button19.Click += new System.EventHandler(this.button19_Click);
//
// button20
//
this.button20.ForeColor = System.Drawing.Color.Red;
this.button20.Location = new System.Drawing.Point(208, 160);
this.button20.Name = "button20";
this.button20.Size = new System.Drawing.Size(40, 30);
this.button20.TabIndex = 20;
this.button20.Text = "-";
this.button20.Click += new System.EventHandler(this.button20_Click);
//
// button21
//
this.button21.ForeColor = System.Drawing.Color.Blue;
this.button21.Location = new System.Drawing.Point(256, 160);
this.button21.Name = "button21";
this.button21.Size = new System.Drawing.Size(40, 30);
this.button21.TabIndex = 21;
this.button21.Text = "1/X";
this.button21.Click += new System.EventHandler(this.button21_Click);
//
// button22
//
this.button22.ForeColor = System.Drawing.Color.Red;
this.button22.Location = new System.Drawing.Point(144, 40);
this.button22.Name = "button22";
this.button22.Size = new System.Drawing.Size(72, 30);
this.button22.TabIndex = 22;
this.button22.Text = "CE";
//
// button23
//
this.button23.ForeColor = System.Drawing.Color.Red;
this.button23.Location = new System.Drawing.Point(224, 40);
this.button23.Name = "button23";
this.button23.Size = new System.Drawing.Size(72, 30);
this.button23.TabIndex = 23;
this.button23.Text = "C";
this.button23.Click += new System.EventHandler(this.button23_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 30);
this.label1.TabIndex = 24;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// button24
//
this.button24.ForeColor = System.Drawing.Color.Blue;
this.button24.Location = new System.Drawing.Point(112, 200);
this.button24.Name = "button24";
this.button24.Size = new System.Drawing.Size(40, 32);
this.button24.TabIndex = 25;
this.button24.Text = "+/-";
this.button24.Click += new System.EventHandler(this.button24_Click);
//
// button25
//
this.button25.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button25.ForeColor = System.Drawing.Color.Blue;
this.button25.Location = new System.Drawing.Point(160, 200);
this.button25.Name = "button25";
this.button25.Size = new System.Drawing.Size(40, 32);
this.button25.TabIndex = 26;
this.button25.Text = ".";
this.button25.Click += new System.EventHandler(this.button25_Click);
//
// button26
//
this.button26.ForeColor = System.Drawing.Color.Red;
this.button26.Location = new System.Drawing.Point(208, 200);
this.button26.Name = "button26";
this.button26.Size = new System.Drawing.Size(40, 32);
this.button26.TabIndex = 27;
this.button26.Text = "+";
this.button26.Click += new System.EventHandler(this.button26_Click);
//
// button27
//
this.button27.ForeColor = System.Drawing.Color.Red;
this.button27.Location = new System.Drawing.Point(256, 200);
this.button27.Name = "button27";
this.button27.Size = new System.Drawing.Size(40, 32);
this.button27.TabIndex = 28;
this.button27.Text = "=";
this.button27.Click += new System.EventHandler(this.button27_Click);
//
// button28
//
this.button28.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button28.Location = new System.Drawing.Point(-8, 0);
this.button28.Name = "button28";
this.button28.Size = new System.Drawing.Size(8, 24);
this.button28.TabIndex = 29;
this.button28.Click += new System.EventHandler(this.button28_Click);
//
// Form1
//
this.AcceptButton = this.button27;
this.AutoScaleBaseSize = new System.Drawing.Size(7, 16);
this.CancelButton = this.button28;
this.ClientSize = new System.Drawing.Size(304, 237);
this.Controls.Add(this.button28);
this.Controls.Add(this.button27);
this.Controls.Add(this.button26);
this.Controls.Add(this.button25);
this.Controls.Add(this.button24);
this.Controls.Add(this.label1);
this.Controls.Add(this.button23);
this.Controls.Add(this.button22);
this.Controls.Add(this.button21);
this.Controls.Add(this.button20);
this.Controls.Add(this.button19);
this.Controls.Add(this.button18);
this.Controls.Add(this.button17);
this.Controls.Add(this.button16);
this.Controls.Add(this.button15);
this.Controls.Add(this.button14);
this.Controls.Add(this.button13);
this.Controls.Add(this.button12);
this.Controls.Add(this.button11);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "小小计算器";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void contextMenu1_Popup(object sender, System.EventArgs e)
{

}

private void button15_Click(object sender, System.EventArgs e)
{
textBox1.Text=textBox1.Text.Substring(0,textBox1.Text.Length-1);
}

private void Form1_Load(object sender, System.EventArgs e)
{

}

private void button26_Click(object sender, System.EventArgs e)
{
if (fh2!="")
{
if (fh=="+")
textBox1.Text=Convert.ToString(cjs1+cjs2);
if (fh=="-")
textBox1.Text=Convert.ToString(cjs1-cjs2);
if (fh=="*")
textBox1.Text=Convert.ToString(cjs1*cjs2);
if (fh=="/")
textBox1.Text=Convert.ToString(cjs1/cjs2);

}
cjs1=Convert.ToDouble(textBox1.Text);
fh="+";
textBox1.Text="";
fh2=fh;
}

private void button20_Click(object sender, System.EventArgs e)
{
if (fh2!="")
{
if (fh=="+")
textBox1.Text=Convert.ToString(cjs1+cjs2);
if (fh=="-")
textBox1.Text=Convert.ToString(cjs1-cjs2);
if (fh=="*")
textBox1.Text=Convert.ToString(cjs1*cjs2);
if (fh=="/")
textBox1.Text=Convert.ToString(cjs1/cjs2);;
}
cjs1=Convert.ToDouble(textBox1.Text);
fh="-";
textBox1.Text="";
fh2=fh;

}

private void button18_Click(object sender, System.EventArgs e)
{
if (fh2!="")
{
if (fh=="+")
textBox1.Text=Convert.ToString(cjs1+cjs2);
if (fh=="-")
textBox1.Text=Convert.ToString(cjs1-cjs2);
if (fh=="*")
textBox1.Text=Convert.ToString(cjs1*cjs2);
if (fh=="/")
textBox1.Text=Convert.ToString(cjs1/cjs2);
}
cjs1=Convert.ToDouble(textBox1.Text);
fh="*";
textBox1.Text="";
fh2=fh;
}

private void button16_Click(object sender, System.EventArgs e)
{if (fh2!="")
{
if (fh=="+")
textBox1.Text=Convert.ToString(cjs1+cjs2);
if (fh=="-")
textBox1.Text=Convert.ToString(cjs1-cjs2);
if (fh=="*")
textBox1.Text=Convert.ToString(cjs1*cjs2);
if (fh=="/")
textBox1.Text=Convert.ToString(cjs1/cjs2);
}
cjs1=Convert.ToDouble(textBox1.Text);
fh="/";
textBox1.Text="";
fh2=fh;
}

private void button17_Click(object sender, System.EventArgs e)
{
cjs1=Convert.ToDouble(textBox1.Text);
textBox1.Text=Convert.ToString(Math.Sqrt(cjs1));
}

private void button19_Click(object sender, System.EventArgs e)
{
cjs1=Convert.ToDouble(textBox1.Text);
}

private void button21_Click(object sender, System.EventArgs e)
{
cjs1=Convert.ToDouble(textBox1.Text);
textBox1.Text=Convert.ToString(1/cjs1);
}

private void button25_Click(object sender, System.EventArgs e)
{
textBox1.Text=textBox1.Text+".";
}

private void button1_Click(object sender, System.EventArgs e)
{
if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button1.Text;
else
textBox1.Text=button1.Text;
}

private void button10_Click(object sender, System.EventArgs e)
{
textBox1.Text=textBox1.Text+button10.Text;
}

private void button2_Click(object sender, System.EventArgs e)
{if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button2.Text;
else
textBox1.Text=button1.Text;
}

private void button3_Click(object sender, System.EventArgs e)
{if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button3.Text;
else
textBox1.Text=button1.Text;
}

private void button4_Click(object sender, System.EventArgs e)
{if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button4.Text;
else
textBox1.Text=button1.Text;
}

private void button5_Click(object sender, System.EventArgs e)
{if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button5.Text;
else
textBox1.Text=button1.Text;
}

private void button6_Click(object sender, System.EventArgs e)
{if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button6.Text;
else
textBox1.Text=button1.Text;
}

private void button7_Click(object sender, System.EventArgs e)
{if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button7.Text;
else
textBox1.Text=button1.Text;
}

private void button8_Click(object sender, System.EventArgs e)
{if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button8.Text;
else
textBox1.Text=button1.Text;
}

private void button9_Click(object sender, System.EventArgs e)
{if (textBox1.Text!="0")
textBox1.Text=textBox1.Text+button9.Text;
else
textBox1.Text=button1.Text;
}

private void button27_Click(object sender, System.EventArgs e)
{
cjs2=Convert.ToDouble(textBox1.Text);
if (fh=="+")
textBox1.Text=Convert.ToString(cjs1+cjs2);
if (fh=="-")
textBox1.Text=Convert.ToString(cjs1-cjs2);
if (fh=="*")
textBox1.Text=Convert.ToString(cjs1*cjs2);
if (fh=="/")
textBox1.Text=Convert.ToString(cjs1/cjs2);

}

private void button23_Click(object sender, System.EventArgs e)
{
textBox1.Text="";
cjs1=0;
cjs2=0;
fh="";

}

private void button24_Click(object sender, System.EventArgs e)
{
textBox1.Text=Convert.ToString(Convert.ToDouble(textBox1.Text)+0);
}
private void button24_DoubleClick(object sender, System.EventArgs e)
{
textBox1.Text=Convert.ToString(0-Convert.ToDouble(textBox1.Text));
}

private void textBox1_TextChanged(object sender, System.EventArgs e)
{

}

private void label1_Click(object sender, System.EventArgs e)
{

}

private void button11_Click(object sender, System.EventArgs e)
{
ccs=0;
textBox1.Text="";
}

private void button12_Click(object sender, System.EventArgs e)
{
ccs=Convert.ToDouble(textBox1.Text);
}

private void button13_Click(object sender, System.EventArgs e)
{
textBox1.Text=Convert.ToString(ccs);
textBox1.Text="";

}

private void button14_Click(object sender, System.EventArgs e)
{
ccs=ccs+Convert.ToDouble(textBox1.Text);
textBox1.Text="";
label1.Text="M";
}

private void button28_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
====================================================================================

本程序为本人自己编写.其中多有不足之处.请广大读者不吝赐教.

可写信到本人邮箱.yjpgyje@163.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: