【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 ...
随机推荐
- UNIX环境编程学习笔记(18)——进程管理之进程控制三部曲
lienhua342014-10-05 1 进程控制三部曲概述 UNIX 系统提供了 fork.exec.exit 和 wait 等基本的进程控制原语.通过这些进程控制原语,我们即可完成对进程创建.执 ...
- storm学习之六-使用Maven 生成jar包多种方式
Maven可以使用mvn package指令对项目进行打包,如果使用java -jar xxx.jar执行运行jar文件,会出现"no main manifest attribute, in ...
- 在Android中,px,dp,dip,sp的不同之处
最近在学习Android开发,一直没有弄清楚px,dp,dip,sp的区别.今天正好有时间,就花时间研究了一下. 众所周知,Android厂商非常多,各种尺寸的Android手机 ...
- localstorage和sessionstorage上手使用记录
通过阅读各路大神对web存储locastorage和sessionstorage的用法解析,自己试用了一下,在此留个备忘. 在项目中,如果用到很多次storage,要存储很多数据,就要把它封装成函数了 ...
- win8.1的ie11无法打开127.0.0.1和本机IP访问
解决方法:把ie11安全选项里的启动保护模式对勾去掉!
- Ruby 面向对象知识详解
Ruby 是纯面向对象的语言,Ruby 中的一切都是以对象的形式出现.Ruby 中的每个值都是一个对象,即使是最原始的东西:字符串.数字,甚至连 true 和 false 都是对象.类本身也是一个对象 ...
- python,如何获取字符串中的子字符串,部分字符串
说明: 比如有一个字符串,python,如何就获取前3位,或者后2位.在此记录下. 操作过程: 1.通过分割符的方式,下标的方式,获取字符串中的子串 >>> text = 'pyth ...
- 关于修改linux hostname的问题,尤其是redhat 7修改hostname的方式
http://blog.csdn.net/the_conquer_zzy/article/details/68064149
- HTML5标签canvas制作平面图
摘要: HTML5规范已经完成了,互联网上已经有数不清的站点使用了HTML5.从现在开始研究HTML5,本文是自己在学习canvas过程中的记录,以备后需. 历史: 这个 HTML 元素是为了客户端矢 ...
- Android 程序打包及签名(转)
为什么要签名??? 开发Android的人这么多,完全有可能大家都把类名,包名起成了一个同样的名字,这时候如何区分?签名这时候就是起区分作用的. 由于开发商可能通过使用相同的Package Name来 ...