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

上传人:re****.1 文档编号:499678620 上传时间:2023-11-28 格式:DOC 页数:20 大小:395.50KB
返回 下载 相关 举报
C编写简易计算器附源代码超详细_第1页
第1页 / 共20页
C编写简易计算器附源代码超详细_第2页
第2页 / 共20页
C编写简易计算器附源代码超详细_第3页
第3页 / 共20页
C编写简易计算器附源代码超详细_第4页
第4页 / 共20页
C编写简易计算器附源代码超详细_第5页
第5页 / 共20页
点击查看更多>>
资源描述

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

1、超详细一、 因为计算器设计的控件太多,不便使用控制台应用程序完成,所以这里使用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,按键【+ - * /】的name值分别修改为btn_a

2、dd、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 System.Collections;using Sys

3、tem.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.Button btn_2;private System

4、.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 btn_9;private System.Windo

5、ws.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.Button btn_equ;private Sy

6、stem.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.Container components = nul

7、l;public CalcForm()/ Windows 窗体设计器支持所必需的/InitializeComponent();/ TODO: 在InitializeComponent 调用后添加任何构造函数代码/ / 清理所有正在使用的资源。/ protected override void Dispose( bool disposing )if( disposing )if (components != null) components.Dispose();base.Dispose( disposing );#region Windows Form Designer generated co

8、de/ / 设计器支持所需的方法- 不要使用代码编辑器修改/ 此方法的内容。/ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CalcForm); this.btn_9 = new System.Windows.Forms.Button(); this.txtShow = new System.Windows.Forms.TextBox()

9、; 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.Windows.Forms.Button(); this.

10、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.Button(); this.btn_sub =

11、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.Button(); this.btn_rev =

12、 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 = System.Drawing.Syst

13、emColors.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 = 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 = ne

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号