代码如下:
usingSystem;
usingSystem.Drawing;
usingSystem.Windows;
usingSystem.Windows.Forms;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
namespacecomput
{
///<summary>
///这是一个计算器的简单实现。
///</summary>
publicclassForm1:System.Windows.Forms.Form
{
#region控件声明
privateSystem.Windows.Forms.TextBoxtxtShow;
privateSystem.Windows.Forms.GroupBoxgroupBox1;
privateSystem.Windows.Forms.Buttonbtn_rev;
privateSystem.Windows.Forms.Buttonbtn_dot;
privateSystem.Windows.Forms.Buttonbtn_add;
privateSystem.Windows.Forms.Buttonbtn_equ;
privateSystem.Windows.Forms.Buttonbtn_sign;
privateSystem.Windows.Forms.Buttonbtn_sub;
privateSystem.Windows.Forms.Buttonbtn_mul;
privateSystem.Windows.Forms.Buttonbtn_0;
privateSystem.Windows.Forms.Buttonbtn_3;
privateSystem.Windows.Forms.Buttonbtn_2;
privateSystem.Windows.Forms.Buttonbtn_1;
privateSystem.Windows.Forms.Buttonbtn_6;
privateSystem.Windows.Forms.Buttonbtn_5;
privateSystem.Windows.Forms.Buttonbtn_4;
privateSystem.Windows.Forms.Buttonbtn_sqrt;
privateSystem.Windows.Forms.Buttonbtn_div;
privateSystem.Windows.Forms.Buttonbtn_7;
privateSystem.Windows.Forms.Buttonbtn_8;
privateSystem.Windows.Forms.Buttonbtn_9;
privateSystem.Windows.Forms.MainMenumainMenu1;
privateSystem.Windows.Forms.MenuItemmenuItem1;
privateSystem.Windows.Forms.Buttonbtn_sqr;
privateSystem.Windows.Forms.MenuItemmenuItem2;
privateSystem.Windows.Forms.MenuItemmenuItem3;
privateSystem.Windows.Forms.MenuItemmenuItem4;
privateSystem.Windows.Forms.MenuItemmenuItem5;
privateSystem.Windows.Forms.MenuItemmenuItem6;
privateSystem.Windows.Forms.Buttonc;
privateSystem.Windows.Forms.Buttonce;
privateSystem.Windows.Forms.MenuItemmenuItem8;
privateSystem.Windows.Forms.MenuItemmenuItem9;
privateSystem.Windows.Forms.MenuItemmenuItem10;
///<summary>
///必需的设计器变量。
///</summary>
privateSystem.ComponentModel.Containercomponents=null;
publicForm1()
{
//
//Windows窗体设计器支持所必需的
//
InitializeComponent();
//
//TODO:在InitializeComponent调用后添加任何构造函数代码
//
}
///<summary>
///清理所有正在使用的资源。
///</summary>
protectedoverridevoidDispose(booldisposing)
{
if(disposing)
{
if(components!=null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#endregion
#region各控件的属性的方法WindowsFormDesignergeneratedcode
///<summary>
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///</summary>
privatevoidInitializeComponent()
{
System.Resources.ResourceManagerresources=newSystem.Resources.ResourceManager(typeof(Form1));
this.txtShow=newSystem.Windows.Forms.TextBox();
this.groupBox1=newSystem.Windows.Forms.GroupBox();
this.c=newSystem.Windows.Forms.Button();
this.ce=newSystem.Windows.Forms.Button();
this.btn_rev=newSystem.Windows.Forms.Button();
this.btn_dot=newSystem.Windows.Forms.Button();
this.btn_add=newSystem.Windows.Forms.Button();
this.btn_equ=newSystem.Windows.Forms.Button();
this.btn_sign=newSystem.Windows.Forms.Button();
this.btn_sub=newSystem.Windows.Forms.Button();
this.btn_mul=newSystem.Windows.Forms.Button();
this.btn_0=newSystem.Windows.Forms.Button();
this.btn_3=newSystem.Windows.Forms.Button();
this.btn_2=newSystem.Windows.Forms.Button();
this.btn_1=newSystem.Windows.Forms.Button();
this.btn_6=newSystem.Windows.Forms.Button();
this.btn_5=newSystem.Windows.Forms.Button();
this.btn_4=newSystem.Windows.Forms.Button();
this.btn_sqrt=newSystem.Windows.Forms.Button();
this.btn_div=newSystem.Windows.Forms.Button();
this.btn_7=newSystem.Windows.Forms.Button();
this.btn_8=newSystem.Windows.Forms.Button();
this.btn_9=newSystem.Windows.Forms.Button();
this.btn_sqr=newSystem.Windows.Forms.Button();
this.mainMenu1=newSystem.Windows.Forms.MainMenu();
this.menuItem1=newSystem.Windows.Forms.MenuItem();
this.menuItem2=newSystem.Windows.Forms.MenuItem();
this.menuItem3=newSystem.Windows.Forms.MenuItem();
this.menuItem4=newSystem.Windows.Forms.MenuItem();
this.menuItem5=newSystem.Windows.Forms.MenuItem();
this.menuItem6=newSystem.Windows.Forms.MenuItem();
this.menuItem8=newSystem.Windows.Forms.MenuItem();
this.menuItem9=newSystem.Windows.Forms.MenuItem();
this.menuItem10=newSystem.Windows.Forms.MenuItem();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
//txtShow
//
this.txtShow.BackColor=System.Drawing.Color.FromArgb(((System.Byte)(192)),((System.Byte)(192)),((System.Byte)(255)));
this.txtShow.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Regular,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.txtShow.ForeColor=System.Drawing.Color.Purple;
this.txtShow.Location=newSystem.Drawing.Point(25,8);
this.txtShow.Name=”txtShow”;
this.txtShow.Size=newSystem.Drawing.Size(228,23);
this.txtShow.TabIndex=1;
this.txtShow.Text=”0.”;
this.txtShow.TextAlign=System.Windows.Forms.HorizontalAlignment.Right;
//
//groupBox1
//
this.groupBox1.Controls.Add(this.c);
this.groupBox1.Controls.Add(this.ce);
this.groupBox1.Controls.Add(this.btn_rev);
this.groupBox1.Controls.Add(this.btn_dot);
this.groupBox1.Controls.Add(this.btn_add);
this.groupBox1.Controls.Add(this.btn_equ);
this.groupBox1.Controls.Add(this.btn_sign);
this.groupBox1.Controls.Add(this.btn_sub);
this.groupBox1.Controls.Add(this.btn_mul);
this.groupBox1.Controls.Add(this.btn_0);
this.groupBox1.Controls.Add(this.btn_3);
this.groupBox1.Controls.Add(this.btn_2);
this.groupBox1.Controls.Add(this.btn_1);
this.groupBox1.Controls.Add(this.btn_6);
this.groupBox1.Controls.Add(this.btn_5);
this.groupBox1.Controls.Add(this.btn_4);
this.groupBox1.Controls.Add(this.btn_sqrt);
this.groupBox1.Controls.Add(this.btn_div);
this.groupBox1.Controls.Add(this.btn_7);
this.groupBox1.Controls.Add(this.btn_8);
this.groupBox1.Controls.Add(this.btn_9);
this.groupBox1.Controls.Add(this.btn_sqr);
this.groupBox1.Location=newSystem.Drawing.Point(24,40);
this.groupBox1.Name=”groupBox1″;
this.groupBox1.Size=newSystem.Drawing.Size(232,184);
this.groupBox1.TabIndex=21;
this.groupBox1.TabStop=false;
this.groupBox1.Text=”计算机区”;
//
//c
//
this.c.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.c.ForeColor=System.Drawing.Color.Red;
this.c.Location=newSystem.Drawing.Point(178,48);
this.c.Name=”c”;
this.c.Size=newSystem.Drawing.Size(36,61);
this.c.TabIndex=41;
this.c.Text=”C”;
this.c.Click+=newSystem.EventHandler(this.btn_Oper);
//
//ce
//
this.ce.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.ce.ForeColor=System.Drawing.Color.Red;
this.ce.Location=newSystem.Drawing.Point(138,16);
this.ce.Name=”ce”;
this.ce.Size=newSystem.Drawing.Size(76,29);
this.ce.TabIndex=40;
this.ce.Text=”CE”;
this.ce.Click+=newSystem.EventHandler(this.btn_Oper);
//
//btn_rev
//
this.btn_rev.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_rev.ForeColor=System.Drawing.Color.Blue;
this.btn_rev.Location=newSystem.Drawing.Point(178,112);
this.btn_rev.Name=”btn_rev”;
this.btn_rev.Size=newSystem.Drawing.Size(36,29);
this.btn_rev.TabIndex=39;
this.btn_rev.Text=”1/x”;
this.btn_rev.Click+=newSystem.EventHandler(this.btn_Oper);
//
//btn_dot
//
this.btn_dot.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_dot.Location=newSystem.Drawing.Point(98,144);
this.btn_dot.Name=”btn_dot”;
this.btn_dot.Size=newSystem.Drawing.Size(36,29);
this.btn_dot.TabIndex=38;
this.btn_dot.Tag=”0″;
this.btn_dot.Text=”.”;
this.btn_dot.Click+=newSystem.EventHandler(this.btn_Oper);
//
//btn_add
//
this.btn_add.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_add.ForeColor=System.Drawing.Color.Red;
this.btn_add.Location=newSystem.Drawing.Point(138,144);
this.btn_add.Name=”btn_add”;
this.btn_add.Size=newSystem.Drawing.Size(36,29);
this.btn_add.TabIndex=37;
this.btn_add.Text=”+”;
this.btn_add.Click+=newSystem.EventHandler(this.btn_Oper);
//
//btn_equ
//
this.btn_equ.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_equ.ForeColor=System.Drawing.Color.Red;
this.btn_equ.Location=newSystem.Drawing.Point(178,144);
this.btn_equ.Name=”btn_equ”;
this.btn_equ.Size=newSystem.Drawing.Size(36,29);
this.btn_equ.TabIndex=36;
this.btn_equ.Text=”=”;
this.btn_equ.Click+=newSystem.EventHandler(this.btn_equ_Click);
//
//btn_sign
//
this.btn_sign.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_sign.ForeColor=System.Drawing.Color.Blue;
this.btn_sign.Location=newSystem.Drawing.Point(58,144);
this.btn_sign.Name=”btn_sign”;
this.btn_sign.Size=newSystem.Drawing.Size(36,29);
this.btn_sign.TabIndex=35;
this.btn_sign.Text=”+/-“;
this.btn_sign.Click+=newSystem.EventHandler(this.btn_Oper);
//
//btn_sub
//
this.btn_sub.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_sub.ForeColor=System.Drawing.Color.Red;
this.btn_sub.Location=newSystem.Drawing.Point(138,112);
this.btn_sub.Name=”btn_sub”;
this.btn_sub.Size=newSystem.Drawing.Size(36,29);
this.btn_sub.TabIndex=34;
this.btn_sub.Text=”-“;
this.btn_sub.Click+=newSystem.EventHandler(this.btn_Oper);
//
//btn_mul
//
this.btn_mul.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_mul.ForeColor=System.Drawing.Color.Red;
this.btn_mul.Location=newSystem.Drawing.Point(138,80);
this.btn_mul.Name=”btn_mul”;
this.btn_mul.Size=newSystem.Drawing.Size(36,29);
this.btn_mul.TabIndex=33;
this.btn_mul.Text=”*”;
this.btn_mul.Click+=newSystem.EventHandler(this.btn_Oper);
//
//btn_0
//
this.btn_0.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_0.ForeColor=System.Drawing.Color.Blue;
this.btn_0.Location=newSystem.Drawing.Point(18,144);
this.btn_0.Name=”btn_0″;
this.btn_0.Size=newSystem.Drawing.Size(36,29);
this.btn_0.TabIndex=32;
this.btn_0.Tag=”0″;
this.btn_0.Text=”0″;
this.btn_0.Click+=newSystem.EventHandler(this.btn_0_Click);
//
//btn_3
//
this.btn_3.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_3.ForeColor=System.Drawing.Color.Blue;
this.btn_3.Location=newSystem.Drawing.Point(98,112);
this.btn_3.Name=”btn_3″;
this.btn_3.Size=newSystem.Drawing.Size(36,29);
this.btn_3.TabIndex=31;
this.btn_3.Tag=”3″;
this.btn_3.Text=”3″;
this.btn_3.Click+=newSystem.EventHandler(this.btn_0_Click);
//
//btn_2
//
this.btn_2.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_2.ForeColor=System.Drawing.Color.Blue;
this.btn_2.Location=newSystem.Drawing.Point(58,112);
this.btn_2.Name=”btn_2″;
this.btn_2.Size=newSystem.Drawing.Size(36,29);
this.btn_2.TabIndex=30;
this.btn_2.Tag=”2″;
this.btn_2.Text=”2″;
this.btn_2.Click+=newSystem.EventHandler(this.btn_0_Click);
//
//btn_1
//
this.btn_1.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_1.ForeColor=System.Drawing.Color.Blue;
this.btn_1.Location=newSystem.Drawing.Point(18,112);
this.btn_1.Name=”btn_1″;
this.btn_1.Size=newSystem.Drawing.Size(36,29);
this.btn_1.TabIndex=29;
this.btn_1.Tag=”1″;
this.btn_1.Text=”1″;
this.btn_1.Click+=newSystem.EventHandler(this.btn_0_Click);
//
//btn_6
//
this.btn_6.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_6.ForeColor=System.Drawing.Color.Blue;
this.btn_6.Location=newSystem.Drawing.Point(98,80);
this.btn_6.Name=”btn_6″;
this.btn_6.Size=newSystem.Drawing.Size(36,29);
this.btn_6.TabIndex=28;
this.btn_6.Tag=”6″;
this.btn_6.Text=”6″;
this.btn_6.Click+=newSystem.EventHandler(this.btn_0_Click);
//
//btn_5
//
this.btn_5.Font=newSystem.Drawing.Font(“宋体”,10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((System.Byte)(134)));
this.btn_5.ForeColor=System.Drawing.Color.Blue;
this.btn_5.Location=newSystem.Drawing.Poin
Cocos2d-x 3.x入门教程(一):基础概念
C++基础入门教程(四):枚举和指针
上述就是C#学习教程:C#编写的windows计算器的实例代码分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/904889.html