C#编写简易计算器(附源代码)超详细(17页).doc
《C#编写简易计算器(附源代码)超详细(17页).doc》由会员分享,可在线阅读,更多相关《C#编写简易计算器(附源代码)超详细(17页).doc(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-C#编写简易计算器(附源代码)超详细-第 17 页超详细一、 因为计算器设计的控件太多,不便使用控制台应用程序完成,所以这里使用Windows窗体应用程序,并命名为Calc,如下图所示:二、 向窗体中拖入需要的控件,如下图所示:(完成效果图)结果显示区(作者博客左边的文本框)是TextBox控件,并修改其name为txtShow ,按键09为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,按
2、键【+ - * /】的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多分支语句编写using System;using System.Drawing;using Sy
3、stem.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace Calc/ / QQ:479340056 温柔一刀C#简易计算器的实现/ public class CalcForm : System.Windows.Forms.Formprivate System.Windows.Forms.Button btn_0;private System.Windows.Forms.Button btn_1;private System.Windows.Forms.B
4、utton btn_2;private System.Windows.Forms.Button btn_3;private System.Windows.Forms.Button btn_4;private System.Windows.Forms.Button btn_5;private System.Windows.Forms.Button btn_6;private System.Windows.Forms.Button btn_7;private System.Windows.Forms.Button btn_8;private System.Windows.Forms.Button
5、btn_9;private System.Windows.Forms.Button btn_add;private System.Windows.Forms.Button btn_sub;private System.Windows.Forms.Button btn_mul;private System.Windows.Forms.Button btn_div;private System.Windows.Forms.Button btn_sqrt;private System.Windows.Forms.Button btn_sign;private System.Windows.Forms
6、.Button btn_equ;private System.Windows.Forms.Button btn_dot;private System.Windows.Forms.Button btn_rev;private System.Windows.Forms.TextBox txtShow;private System.Windows.Forms.Button btn_sqr; private PictureBox pictureBox1; private LinkLabel linkLabel1;/ / 必需的设计器变量。/ private System.ComponentModel.
7、Container components = null;public CalcForm()/ Windows 窗体设计器支持所必需的InitializeComponent();/ TODO: 在InitializeComponent 调用后添加任何构造函数代码/ / 清理所有正在使用的资源。/ protected override void Dispose( bool disposing )if( disposing )if (components != null) components.Dispose();base.Dispose( disposing );#region Windows F
8、orm Designer generated code/ / 设计器支持所需的方法- 不要使用代码编辑器修改/ 此方法的内容。/ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CalcForm); this.btn_9 = new System.Windows.Forms.Button(); this.txtShow = new Syste
9、m.Windows.Forms.TextBox(); this.btn_8 = new System.Windows.Forms.Button(); this.btn_7 = new System.Windows.Forms.Button(); this.btn_div = new System.Windows.Forms.Button(); this.btn_sqrt = new System.Windows.Forms.Button(); this.btn_4 = new System.Windows.Forms.Button(); this.btn_5 = new System.Wind
10、ows.Forms.Button(); this.btn_6 = new System.Windows.Forms.Button(); this.btn_1 = new System.Windows.Forms.Button(); this.btn_2 = new System.Windows.Forms.Button(); this.btn_3 = new System.Windows.Forms.Button(); this.btn_0 = new System.Windows.Forms.Button(); this.btn_mul = new System.Windows.Forms.
11、Button(); this.btn_sub = new System.Windows.Forms.Button(); this.btn_sign = new System.Windows.Forms.Button(); this.btn_equ = new System.Windows.Forms.Button(); this.btn_add = new System.Windows.Forms.Button(); this.btn_dot = new System.Windows.Forms.Button(); this.btn_sqr = new System.Windows.Forms
12、.Button(); this.btn_rev = new System.Windows.Forms.Button(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); (System.ComponentModel.ISupportInitialize)(this.pictureBox1).BeginInit(); this.SuspendLayout(); / btn_9 this.btn_9.BackColor
13、= 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.Fo
14、nt = new System.Drawing.Font(黑体, 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (byte)(134); this.btn_9.ForeColor = System.Drawing.Color.Black; this.btn_9.Location = new System.Drawing.Point(126, 37); this.btn_9.Name = btn_9; this.btn_9.Size = new System.Drawing.Size(59, 31
15、); this.btn_9.TabIndex = 0; this.btn_9.Tag = 9; this.btn_9.Text = 9; this.btn_9.UseVisualStyleBackColor = false; this.btn_9.Click += new System.EventHandler(this.btn_0_Click); / txtShow this.txtShow.Location = new System.Drawing.Point(4, 6); this.txtShow.Name = txtShow; this.txtShow.ReadOnly = true;
16、 this.txtShow.Size = new System.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.Cent
17、er; this.btn_8.FlatAppearance.MouseDownBackColor = System.Drawing.SystemColors.ButtonFace; this.btn_8.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_8.Font = new System.Drawing.Font(黑体, 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (byte)(134
18、); this.btn_8.ForeColor = System.Drawing.Color.Black; this.btn_8.Location = new System.Drawing.Point(66, 37); this.btn_8.Name = btn_8; this.btn_8.Size = new System.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
19、.btn_8.Click += new System.EventHandler(this.btn_0_Click); / 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.
20、btn_7.FlatAppearance.MouseOverBackColor = System.Drawing.Color.WhiteSmoke; this.btn_7.Font = new System.Drawing.Font(黑体, 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (byte)(134); this.btn_7.ForeColor = System.Drawing.Color.Black; this.btn_7.Location = new System.Drawing.P
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C# 编写 简易 计算器 源代码 详细 17
限制150内