- ·上一篇文章:用Visual C#中轻松浏览数据库记录
- ·下一篇文章:用C#写计算器程序(一)
用C#写计算器程序(二)
源程序
//基本的计算器
//蚕蛹 2001.11.26
//Using C#
//E-mail:sillnet@hotmail.com
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace wincalc
{
///
/// Summary description for calcForm.
///
public class calcForm : System.Windows.Forms.Form
{
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 bClr;
private System.Windows.Forms.Button bDot;
private System.Windows.Forms.Button bPlus;
private System.Windows.Forms.Button bSub;
private System.Windows.Forms.Button bMul;
private System.Windows.Forms.Button bDiv;
private System.Windows.Forms.Button bEqu;
private System.Windows.Forms.TextBox txtCalc;
//以下是要添加的代码
//定义变量
Double dblAcc;
Double dblSec;
bool blnClear,blnFrstOpen;
String strOper;
//以上是添加的代码
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public calcForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
//以下是要添加的代码
//初始化设量
dblAcc=0;
dblSec=0;
blnFrstOpen=true;
blnClear=true;
strOper=new string('=',1);
//以上是添加的代码
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.bPlus = new System.Windows.Forms.Button();
this.bMul = new System.Windows.Forms.Button();
this.bDot = new System.Windows.Forms.Button();
this.txtCalc = new System.Windows.Forms.TextBox();
this.bClr = new System.Windows.Forms.Button();
this.bDiv = new System.Windows.Forms.Button();
this.bSub = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.bEqu = new System.Windows.Forms.Button();
this.button10 = 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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// bPlus
//
this.bPlus.BackColor = System.Drawing.SystemColors.Control;
this.bPlus.ForeColor = System.Drawing.SystemColors.ControlText;
this.bPlus.Location = new System.Drawing.Point(208, 112);
this.bPlus.Name = "bPlus";
this.bPlus.Size = new System.Drawing.Size(32, 80);
this.bPlus.TabIndex = 1;
this.bPlus.Text = "+";
//以下是要添加的代码
bPlus.Click += new System.EventHandler(this.btn_Oper);
//以上是添加的代码
//
// bMul
//
this.bMul.Location = new System.Drawing.Point(160, 112);
this.bMul.Name = "bMul";
this.bMul.Size = new System.Drawing.Size(32, 32);
this.bMul.TabIndex = 1;
this.bMul.Text = "*";
//以下是要添加的代码
bMul.Click += new System.EventHandler(this.btn_Oper);
//以上是添加的代码
//
// bDot
//
this.bDot.ForeColor = System.Drawing.Color.Black;
this.bDot.Location = new System.Drawing.Point(112, 208);
this.bDot.Name = "bDot";
this.bDot.Size = new System.Drawing.Size(32, 32);
this.bDot.TabIndex = 0;
this.bDot.Text = ".";
//以下是要添加的代码
bDot.Click += new System.EventHandler(this.btn_clk);
//以上是添加的代码
//
// txtCalc
//
this.txtCalc.Location = new System.Drawing.Point(16, 24);
this.txtCalc.Name = "txtCalc";
this.txtCalc.ReadOnly = true;
this.txtCalc.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.txtCalc.Size = new System.Drawing.Size(224, 21);
this.txtCalc.TabIndex = 2;
this.txtCalc.Text = "";
//
// bClr
//
this.bClr.BackColor = System.Drawing.SystemColors.Control;
this.bClr.ForeColor = System.Drawing.SystemColors.ControlText;
this.bClr.Location = new System.Drawing.Point(208, 64);
this.bClr.Name = "bClr";
this.bClr.Size = new System.Drawing.Size(32, 32);
this.bClr.TabIndex = 0;
this.bClr.Text = "AC";
//以下是要添加的代码
bClr.Click += new System.EventHandler(this.btn_clr);
//以上是添加的代码
//
// bDiv
//
this.bDiv.Location = new System.Drawing.Point(160, 160);
this.bDiv.Name = "bDiv";
this.bDiv.Size = new System.Drawing.Size(32, 32);
this.bDiv.TabIndex = 1;
this.bDiv.Text = "/";
//以下是要添加的代码
bDiv.Click += new System.EventHandler(this.btn_Oper);
//以上是添加的代码
//
// bSub
//
this.bSub.Location = new System.Drawing.Point(160, 64);
this.bSub.Name = "bSub";
this.bSub.Size = new System.Drawing.Size(32, 32);
this.bSub.TabIndex = 1;
this.bSub.Text
