C#编写简易计算器附源代码超详细.docx

上传人:b****1 文档编号:247417 上传时间:2023-04-28 格式:DOCX 页数:32 大小:59.86KB
下载 相关 举报
C#编写简易计算器附源代码超详细.docx_第1页
第1页 / 共32页
C#编写简易计算器附源代码超详细.docx_第2页
第2页 / 共32页
C#编写简易计算器附源代码超详细.docx_第3页
第3页 / 共32页
C#编写简易计算器附源代码超详细.docx_第4页
第4页 / 共32页
C#编写简易计算器附源代码超详细.docx_第5页
第5页 / 共32页
C#编写简易计算器附源代码超详细.docx_第6页
第6页 / 共32页
C#编写简易计算器附源代码超详细.docx_第7页
第7页 / 共32页
C#编写简易计算器附源代码超详细.docx_第8页
第8页 / 共32页
C#编写简易计算器附源代码超详细.docx_第9页
第9页 / 共32页
C#编写简易计算器附源代码超详细.docx_第10页
第10页 / 共32页
C#编写简易计算器附源代码超详细.docx_第11页
第11页 / 共32页
C#编写简易计算器附源代码超详细.docx_第12页
第12页 / 共32页
C#编写简易计算器附源代码超详细.docx_第13页
第13页 / 共32页
C#编写简易计算器附源代码超详细.docx_第14页
第14页 / 共32页
C#编写简易计算器附源代码超详细.docx_第15页
第15页 / 共32页
C#编写简易计算器附源代码超详细.docx_第16页
第16页 / 共32页
C#编写简易计算器附源代码超详细.docx_第17页
第17页 / 共32页
C#编写简易计算器附源代码超详细.docx_第18页
第18页 / 共32页
C#编写简易计算器附源代码超详细.docx_第19页
第19页 / 共32页
C#编写简易计算器附源代码超详细.docx_第20页
第20页 / 共32页
亲,该文档总共32页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C#编写简易计算器附源代码超详细.docx

《C#编写简易计算器附源代码超详细.docx》由会员分享,可在线阅读,更多相关《C#编写简易计算器附源代码超详细.docx(32页珍藏版)》请在冰点文库上搜索。

C#编写简易计算器附源代码超详细.docx

C#编写简易计算器附源代码超详细

超详细

一、因为计算器设计的控件太多,不便使用控制台应用程序完成,所以这里使用Windows窗体应用程序,并命名为Calc,如下图所示:

二、向窗体中拖入需要的控件,如下图所示:

〔完成效果图

结果显示区〔作者博客左边的文本框是TextBox控件,并修改其name为txtShow,按键0~9为Button控件,并将其name分别修改为btn_0、btn_1、btn_2、btn_3、btn_4、btn_5、btn_6、btn_7、btn_8、btn_9;按键[负数]的name值修改为btn_sign,按键[.]的name修改为btn_dot,按键[+-*/]的name值分别修改为btn_add、btn_sub、btn_mul、btn_div,按键[=]的name值修改为btn_equ,按键[倒数]的name值修改为btn_rev,按键[平方]的name值修改为btn_sqr,按键[开方]的name值修改为btn_sqrt。

右边的计算器图片空间是PictureBox,作者博客控件是LinkLabel,可以不添加,以上所有控件均可按照需求添加,只保留自己需要的按钮控件和textbox控件即可。

三、代码部分〔含解释,采用switch多分支语句编写

usingSystem;

usingSystem.Drawing;

usingSystem.Collections;

usingSystemponentModel;

usingSystem.Windows.Forms;

usingSystem.Data;

namespaceCalc

{

///

///QQ:

479340056温柔一刀C#简易计算器的实现

///

publicclassCalcForm:

System.Windows.Forms.Form

{

privateSystem.Windows.Forms.Buttonbtn_0;

privateSystem.Windows.Forms.Buttonbtn_1;

privateSystem.Windows.Forms.Buttonbtn_2;

privateSystem.Windows.Forms.Buttonbtn_3;

privateSystem.Windows.Forms.Buttonbtn_4;

privateSystem.Windows.Forms.Buttonbtn_5;

privateSystem.Windows.Forms.Buttonbtn_6;

privateSystem.Windows.Forms.Buttonbtn_7;

privateSystem.Windows.Forms.Buttonbtn_8;

privateSystem.Windows.Forms.Buttonbtn_9;

privateSystem.Windows.Forms.Buttonbtn_add;

privateSystem.Windows.Forms.Buttonbtn_sub;

privateSystem.Windows.Forms.Buttonbtn_mul;

privateSystem.Windows.Forms.Buttonbtn_div;

privateSystem.Windows.Forms.Buttonbtn_sqrt;

privateSystem.Windows.Forms.Buttonbtn_sign;

privateSystem.Windows.Forms.Buttonbtn_equ;

privateSystem.Windows.Forms.Buttonbtn_dot;

privateSystem.Windows.Forms.Buttonbtn_rev;

privateSystem.Windows.Forms.TextBoxtxtShow;

privateSystem.Windows.Forms.Buttonbtn_sqr;

privatePictureBoxpictureBox1;

privateLinkLabellinkLabel1;

///

///必需的设计器变量。

///

privateSystemponentModel.Containercomponents=null;

publicCalcForm<>

{

//

//Windows窗体设计器支持所必需的

//

InitializeComponent<>;

//

//TODO:

在InitializeComponent调用后添加任何构造函数代码

//

}

///

///清理所有正在使用的资源。

///

protectedoverridevoidDispose

{

if

{

if

=null>

{

components.Dispose<>;

}

}

base.Dispose;

}

#regionWindowsFormDesignergeneratedcode

///

///设计器支持所需的方法-不要使用代码编辑器修改

///此方法的内容。

///

privatevoidInitializeComponent<>

{

SystemponentModelponentResourceManagerresources=newSystemponentModelponentResourceManager>;

this.btn_9=newSystem.Windows.Forms.Button<>;

this.txtShow=newSystem.Windows.Forms.TextBox<>;

this.btn_8=newSystem.Windows.Forms.Button<>;

this.btn_7=newSystem.Windows.Forms.Button<>;

this.btn_div=newSystem.Windows.Forms.Button<>;

this.btn_sqrt=newSystem.Windows.Forms.Button<>;

this.btn_4=newSystem.Windows.Forms.Button<>;

this.btn_5=newSystem.Windows.Forms.Button<>;

this.btn_6=newSystem.Windows.Forms.Button<>;

this.btn_1=newSystem.Windows.Forms.Button<>;

this.btn_2=newSystem.Windows.Forms.Button<>;

this.btn_3=newSystem.Windows.Forms.Button<>;

this.btn_0=newSystem.Windows.Forms.Button<>;

this.btn_mul=newSystem.Windows.Forms.Button<>;

this.btn_sub=newSystem.Windows.Forms.Button<>;

this.btn_sign=newSystem.Windows.Forms.Button<>;

this.btn_equ=newSystem.Windows.Forms.Button<>;

this.btn_add=newSystem.Windows.Forms.Button<>;

this.btn_dot=newSystem.Windows.Forms.Button<>;

this.btn_sqr=newSystem.Windows.Forms.Button<>;

this.btn_rev=newSystem.Windows.Forms.Button<>;

this.pictureBox1=newSystem.Windows.Forms.PictureBox<>;

this.linkLabel1=newSystem.Windows.Forms.LinkLabel<>;

<>.BeginInit<>;

this.SuspendLayout<>;

//

//btn_9

//

this.btn_9.BackColor=System.Drawing.SystemColors.ActiveBorder;

this.btn_9.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Center;

this.btn_9.FlatAppearance.MouseDownBackColor=System.Drawing.SystemColors.ButtonFace;

this.btn_9.FlatAppearance.MouseOverBackColor=System.Drawing.Color.WhiteSmoke;

this.btn_9.Font=newSystem.Drawing.Font<"黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,<<134>>>;

this.btn_9.ForeColor=System.Drawing.Color.Black;

this.btn_9.Location=newSystem.Drawing.Point<126,37>;

this.btn_9.Name="btn_9";

this.btn_9.Size=newSystem.Drawing.Size<59,31>;

this.btn_9.TabIndex=0;

this.btn_9.Tag="9";

this.btn_9.Text="9";

this.btn_9.UseVisualStyleBackColor=false;

this.btn_9.Click+=newSystem.EventHandler;

//

//txtShow

//

this.txtShow.Location=newSystem.Drawing.Point<4,6>;

this.txtShow.Name="txtShow";

this.txtShow.ReadOnly=true;

this.txtShow.Size=newSystem.Drawing.Size<242,21>;

this.txtShow.TabIndex=1;

this.txtShow.TextAlign=System.Windows.Forms.HorizontalAlignment.Right;

//

//btn_8

//

this.btn_8.BackColor=System.Drawing.SystemColors.ActiveBorder;

this.btn_8.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Center;

this.btn_8.FlatAppearance.MouseDownBackColor=System.Drawing.SystemColors.ButtonFace;

this.btn_8.FlatAppearance.MouseOverBackColor=System.Drawing.Color.WhiteSmoke;

this.btn_8.Font=newSystem.Drawing.Font<"黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,<<134>>>;

this.btn_8.ForeColor=System.Drawing.Color.Black;

this.btn_8.Location=newSystem.Drawing.Point<66,37>;

this.btn_8.Name="btn_8";

this.btn_8.Size=newSystem.Drawing.Size<59,31>;

this.btn_8.TabIndex=2;

this.btn_8.Tag="8";

this.btn_8.Text="8";

this.btn_8.UseVisualStyleBackColor=false;

this.btn_8.Click+=newSystem.EventHandler;

//

//btn_7

//

this.btn_7.BackColor=System.Drawing.SystemColors.ActiveBorder;

this.btn_7.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Center;

this.btn_7.FlatAppearance.MouseDownBackColor=System.Drawing.SystemColors.ButtonFace;

this.btn_7.FlatAppearance.MouseOverBackColor=System.Drawing.Color.WhiteSmoke;

this.btn_7.Font=newSystem.Drawing.Font<"黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,<<134>>>;

this.btn_7.ForeColor=System.Drawing.Color.Black;

this.btn_7.Location=newSystem.Drawing.Point<4,37>;

this.btn_7.Name="btn_7";

this.btn_7.Size=newSystem.Drawing.Size<59,31>;

this.btn_7.TabIndex=3;

this.btn_7.Tag="7";

this.btn_7.Text="7";

this.btn_7.UseVisualStyleBackColor=false;

this.btn_7.Click+=newSystem.EventHandler;

//

//btn_div

//

this.btn_div.BackColor=System.Drawing.SystemColors.ActiveBorder;

this.btn_div.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Center;

this.btn_div.FlatAppearance.MouseDownBackColor=System.Drawing.SystemColors.ButtonFace;

this.btn_div.FlatAppearance.MouseOverBackColor=System.Drawing.Color.WhiteSmoke;

this.btn_div.Font=newSystem.Drawing.Font<"黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,<<134>>>;

this.btn_div.ForeColor=System.Drawing.Color.Red;

this.btn_div.Location=newSystem.Drawing.Point<187,37>;

this.btn_div.Name="btn_div";

this.btn_div.Size=newSystem.Drawing.Size<59,31>;

this.btn_div.TabIndex=4;

this.btn_div.Text="/";

this.btn_div.UseVisualStyleBackColor=false;

this.btn_div.Click+=newSystem.EventHandler;

//

//btn_sqrt

//

this.btn_sqrt.BackColor=System.Drawing.SystemColors.ActiveBorder;

this.btn_sqrt.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Center;

this.btn_sqrt.FlatAppearance.MouseDownBackColor=System.Drawing.SystemColors.ButtonFace;

this.btn_sqrt.FlatAppearance.MouseOverBackColor=System.Drawing.Color.WhiteSmoke;

this.btn_sqrt.Font=newSystem.Drawing.Font<"黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,<<134>>>;

this.btn_sqrt.ForeColor=System.Drawing.Color.Black;

this.btn_sqrt.Location=newSystem.Drawing.Point<253,37>;

this.btn_sqrt.Name="btn_sqrt";

this.btn_sqrt.Size=newSystem.Drawing.Size<59,31>;

this.btn_sqrt.TabIndex=5;

this.btn_sqrt.Text="开方";

this.btn_sqrt.UseVisualStyleBackColor=false;

this.btn_sqrt.Click+=newSystem.EventHandler;

//

//btn_4

//

this.btn_4.BackColor=System.Drawing.SystemColors.ActiveBorder;

this.btn_4.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Center;

this.btn_4.FlatAppearance.MouseDownBackColor=System.Drawing.SystemColors.ButtonFace;

this.btn_4.FlatAppearance.MouseOverBackColor=System.Drawing.Color.WhiteSmoke;

this.btn_4.Font=newSystem.Drawing.Font<"黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,<<134>>>;

this.btn_4.ForeColor=System.Drawing.Color.Black;

this.btn_4.Location=newSystem.Drawing.Point<4,72>;

this.btn_4.Name="btn_4";

this.btn_4.Size=newSystem.Drawing.Size<59,31>;

this.btn_4.TabIndex=6;

this.btn_4.Tag="4";

this.btn_4.Text="4";

this.btn_4.UseVisualStyleBackColor=false;

this.btn_4.Click+=newSystem.EventHandler;

//

//btn_5

//

this.btn_5.BackColor=System.Drawing.SystemColors.ActiveBorder;

this.btn_5.BackgroundImageLayout=System.Windows.Forms.ImageLayout.Center;

this.btn_5.FlatAppearance.MouseDownBackColor=System.Drawing.SystemColors.ButtonFace;

this.btn_5.FlatAppearance.MouseOverBackColor=System.Drawing.Color.WhiteSmoke;

this.btn_5.Font=newSystem.Drawing.Font<"黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,<<134>>>;

this.btn_5.ForeColor=System.Drawing.Color.Black;

this.btn_5.Location=newSystem.Drawing.Point<66,72>;

this.btn_5.Name="btn_5";

this.btn_5.Size=newSystem.Drawing.Size<59,31>;

this.btn_5.TabIndex=7;

this.btn_5.Tag="5";

this.btn_5.Text="5";

this.btn_5.UseVisualStyleBackColor=

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2