【C#】简单计算器源代码
form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms; namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void clear_Click(object sender, EventArgs e)
{
box1.Text = "";
box2.Text = "";
jg.Text = "";
box1.Focus(); } private void equal_Click(object sender, EventArgs e)
{
string b1 = box1.Text;
string b2 = box2.Text;
string fh = choice.Text;
double sum;
if (string.IsNullOrEmpty(b1) || string.IsNullOrEmpty(b2))
{
MessageBox.Show("请输入要计算的数据");
return;
} double _a = ;
bool _aParse = double.TryParse(b1, out _a);
double _b = ;
bool _bParse = double.TryParse(b2, out _b);
if (!_aParse || !_bParse)
{
MessageBox.Show("请输入数字");
return;
}
if (string.IsNullOrEmpty(fh))
{
MessageBox.Show("请选择计算符号");
return;
} switch (choice.Text.ToString())
{
case "+": sum = _a + _b;
jg.Text = Convert.ToString(sum = _a + _b);
MessageBox.Show(Convert.ToString(sum = _a + _b));
break;
case "-": sum = _a - _b;
jg.Text = Convert.ToString(sum = _a - _b);
MessageBox.Show(Convert.ToString(sum = _a - _b));
break;
case "*": sum = _a * _b;
jg.Text = Convert.ToString(sum = _a * _b);
MessageBox.Show(Convert.ToString(sum = _a * _b));
break;
case "/": sum = _a / _b;
jg.Text = Convert.ToString(sum = _a / _b);
MessageBox.Show(Convert.ToString(sum = _a / _b));
break;
}
clear.Focus();
} private void Form1_Load(object sender, EventArgs e)
{
choice.Items.Add("+");
choice.Items.Add("-");
choice.Items.Add("*");
choice.Items.Add("/");
}
} }
form.Designer.cs
namespace WindowsApplication2
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.box1 = new System.Windows.Forms.TextBox();
this.jg = new System.Windows.Forms.Label();
this.equal = new System.Windows.Forms.Button();
this.box2 = new System.Windows.Forms.TextBox();
this.clear = new System.Windows.Forms.Button();
this.choice = new System.Windows.Forms.ComboBox();
this.tishi = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// box1
//
this.box1.Location = new System.Drawing.Point(, );
this.box1.Name = "box1";
this.box1.Size = new System.Drawing.Size(, );
this.box1.TabIndex = ;
//
// jg
//
this.jg.AutoSize = true;
this.jg.Location = new System.Drawing.Point(, );
this.jg.Name = "jg";
this.jg.Size = new System.Drawing.Size(, );
this.jg.TabIndex = ;
this.jg.Text = "_____";
//
// equal
//
this.equal.Location = new System.Drawing.Point(, );
this.equal.Name = "equal";
this.equal.Size = new System.Drawing.Size(, );
this.equal.TabIndex = ;
this.equal.Text = "等于";
this.equal.UseVisualStyleBackColor = true;
this.equal.Click += new System.EventHandler(this.equal_Click);
//
// box2
//
this.box2.Location = new System.Drawing.Point(, );
this.box2.Name = "box2";
this.box2.Size = new System.Drawing.Size(, );
this.box2.TabIndex = ;
//
// clear
//
this.clear.Location = new System.Drawing.Point(, );
this.clear.Name = "clear";
this.clear.Size = new System.Drawing.Size(, );
this.clear.TabIndex = ;
this.clear.Text = "清除";
this.clear.UseVisualStyleBackColor = true;
this.clear.Click += new System.EventHandler(this.clear_Click);
//
// choice
//
this.choice.FormattingEnabled = true;
this.choice.Location = new System.Drawing.Point(, );
this.choice.Name = "choice";
this.choice.Size = new System.Drawing.Size(, );
this.choice.TabIndex = ;
this.choice.Text = "+";
//
// tishi
//
this.tishi.AutoSize = true;
this.tishi.Location = new System.Drawing.Point(, );
this.tishi.Name = "tishi";
this.tishi.Size = new System.Drawing.Size(, );
this.tishi.TabIndex = ;
this.tishi.Text = "亲,请选择计算符号哦~";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.tishi);
this.Controls.Add(this.choice);
this.Controls.Add(this.clear);
this.Controls.Add(this.box2);
this.Controls.Add(this.equal);
this.Controls.Add(this.jg);
this.Controls.Add(this.box1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox box1;
private System.Windows.Forms.Label jg;
private System.Windows.Forms.Button equal;
private System.Windows.Forms.TextBox box2;
private System.Windows.Forms.Button clear;
private System.Windows.Forms.ComboBox choice;
private System.Windows.Forms.Label tishi; }
}
【C#】简单计算器源代码的更多相关文章
- 一个用WPF做的简单计算器源代码
一.界面设计XAML代码 <Window x:Class="fengjisuanqi.MainWindow" xmlns="http://schemas.micro ...
- 每天2个android小例子----简单计算器源代码
通过Android4.0 网格布局GridLayout来实现一个简单的计算器界面布局 package com.android.xiong.gridlayoutTest; import java.mat ...
- Android之一个简单计算器源代码
通过Android4.0 网格布局GridLayout来实现一个简单的计算器界面布局 源码如下(欢迎大家指导 批评 ) package com.android.xiong.gridlayoutTe ...
- 简单计算器的C实现-函数指针,main函数传参
/** 程序功能:简单计算器,实现加减乘除平方* 作者版本日期:2015.11.08 zhouhb OK* 源代码:李明 <新概念C语言培训>第33集 C语言Shell命令解释器的实现* ...
- 1.C#WinForm基础制作简单计算器
利用c#语言编写简单计算器: 核心知识点: MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex));//下拉序号 MessageBox.S ...
- 菜鸟学Android编程——简单计算器《一》
菜鸟瞎搞,高手莫进 本人菜鸟一枚,最近在学Android编程,网上看了一些视频教程,于是想着平时手机上的计算器应该很简单,自己何不尝试着做一个呢? 于是就冒冒失失的开撸了. 简单计算器嘛,功能当然很少 ...
- PAT 06-1 简单计算器
想看一般简单计算器实现的看客不好意思了,这不是你想要点东西,此处题设为“只能进行加减乘除”.“都是整数”.”优先级相同“和"从左到右".此题来自PAT(http://www.pat ...
- php大力力 [005节] php大力力简单计算器001
2015-08-22 php大力力005. php大力力简单计算器001: 上网看视频,看了半天,敲击代码,如下: <html> <head> <title>简单计 ...
- PHP实现简单计算器
<!--简单的计算器--> <!DOCTYPE html> <html> <head> <title>PHP实现简单计算器</titl ...
随机推荐
- 【Math】矩阵求导
https://en.wikipedia.org/wiki/Matrix_calculus http://blog.sina.com.cn/s/blog_7959e7ed0100w2b3.html
- windows2008 使用nginx 反向代理实现负载均衡解决HTTPS 证书问题
由于项目需要 负载均衡由NBL 转成nginx 反向代理.考虑都是https模块,所以证书成了个难题. 解决方案: 1.下载openssl(windows 安装包) 2.打开bin/下面的openss ...
- [CNN] What is Convolutional Neural Network
Ref: 从LeNet-5看卷积神经网络CNNs 关于这篇论文的一些博文的QAC: 1. 基本原理 MLP(Multilayer Perceptron,多层感知器)是一种前向神经网络(如下图所示),相 ...
- JBOSS 数据源配置并使用JNDI调用
-- 本文出自sleest (感谢yangjj ^_^) 场景分析: 某天系统的数据库维护方要求进行DG备库容灾演练,要把生产用RAC库模拟宕机并转移至DG备库上,由于是failover而不是swit ...
- Linux+Redis实战教程_day03_1、Redis-LinkedList【重点】
1.redis-LinkedList[重点] Java List : 数组ArrayList 链表LinkedList 为什么redis选取了链表? Redis操作中,最多的操作是进行元素的增删 使用 ...
- web.xml 整合 SpringMVC
啦啦啦 <context-param> <param-name>defaultHtmlEscape</param-name> <param-value> ...
- ios开发之--WKWebView的使用
WKWebView是ios 8 出来的,是为了解决UIWebView卡慢,占用内存过大的问题. 在以往时候,如果用UIWebView加载加载网页的时候,卡慢现象会很严重,有时候往往会卡到一个页面无法动 ...
- Weblogic(CVE-2017-10271)漏洞复现
WebLogic XMLDecoder反序列化漏洞(CVE-2017-10271) 漏洞编号:CVE-2017-10271 漏洞描述:WebLogic WLS组件中存在CVE-2017-10271远程 ...
- 在线电路编程 (ICP)
通过在线电路编程(ICP)编程Flash.如果产品在开发中,或在终端客户的产品需要固件升级,采用硬件编程模式非常困难且不方便.采用ICP方式将很简单,且不需要将微控制器从板上拆下来.ICP方式同样允许 ...
- Cookie和Session机制详解
会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...