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#】简单计算器源代码的更多相关文章

  1. 一个用WPF做的简单计算器源代码

    一.界面设计XAML代码 <Window x:Class="fengjisuanqi.MainWindow" xmlns="http://schemas.micro ...

  2. 每天2个android小例子----简单计算器源代码

    通过Android4.0 网格布局GridLayout来实现一个简单的计算器界面布局 package com.android.xiong.gridlayoutTest; import java.mat ...

  3. Android之一个简单计算器源代码

    通过Android4.0 网格布局GridLayout来实现一个简单的计算器界面布局   源码如下(欢迎大家指导 批评 ) package com.android.xiong.gridlayoutTe ...

  4. 简单计算器的C实现-函数指针,main函数传参

    /** 程序功能:简单计算器,实现加减乘除平方* 作者版本日期:2015.11.08 zhouhb OK* 源代码:李明 <新概念C语言培训>第33集 C语言Shell命令解释器的实现* ...

  5. 1.C#WinForm基础制作简单计算器

    利用c#语言编写简单计算器: 核心知识点: MessageBox.Show(Convert.ToString(comboBox1.SelectedIndex));//下拉序号 MessageBox.S ...

  6. 菜鸟学Android编程——简单计算器《一》

    菜鸟瞎搞,高手莫进 本人菜鸟一枚,最近在学Android编程,网上看了一些视频教程,于是想着平时手机上的计算器应该很简单,自己何不尝试着做一个呢? 于是就冒冒失失的开撸了. 简单计算器嘛,功能当然很少 ...

  7. PAT 06-1 简单计算器

    想看一般简单计算器实现的看客不好意思了,这不是你想要点东西,此处题设为“只能进行加减乘除”.“都是整数”.”优先级相同“和"从左到右".此题来自PAT(http://www.pat ...

  8. php大力力 [005节] php大力力简单计算器001

    2015-08-22 php大力力005. php大力力简单计算器001: 上网看视频,看了半天,敲击代码,如下: <html> <head> <title>简单计 ...

  9. PHP实现简单计算器

    <!--简单的计算器--> <!DOCTYPE html> <html> <head> <title>PHP实现简单计算器</titl ...

随机推荐

  1. 用Fiddler查看 Android/iOS 网络请求

    1.下载fiddler,尽量到官方网站找最新的版本 我这里也放了一个:http://files.cnblogs.com/xiaokang088/fiddler4setup.zip 2. 打开Fiddl ...

  2. Nine-patch

    http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch   This NinePatch defi ...

  3. python中,如有个非常长的字符串,在写的时候如何将其分隔

    说明: 比如,有个长字符串,Put several strings within parentheses to have them joined together.但是我在写脚本的时候, 想要放在多行 ...

  4. sql server 存储过程基础知识

    转自家园大哥博文http://www.cnblogs.com/jiajiayuan/archive/2011/06/15/2081201.html 什么是存储过程呢?存储过程就是作为可执行对象存放在数 ...

  5. Android中显示照片的Exif信息

    package com.hyzhou.pngexifdemo; import android.media.ExifInterface; import android.os.Bundle; import ...

  6. 【VirtualBox】设置NAT端口映射-SSH登录

    参考地址: http://www.cnblogs.com/sky20081816/p/3951889.html http://blog.csdn.net/jiangsyace/article/deta ...

  7. Windows 2012 R2 安装Nessus

    1.nessus官网注册 注册地址:https://www.tenable.com/products/nessus-home Name字段随意,邮箱需要填写自己的,方便接受注册码 2.注册后,登录邮箱 ...

  8. SharePoint如何模拟用户

    try { SPSecurity.RunWithElevatedPrivileges(delegate() //用此方法模拟管理员账户运行此事件处理程序 { SPWeb web = SPContext ...

  9. Nginx(七)-- 反向代理

    1.概念  反向代理(Reverse Proxy)方式是指以代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络上的服务器:并将从服务器上得到的结果返回给Internet上请求连接的 ...

  10. Kafka Java API操作topic

    Kafka官方提供了两个脚本来管理topic,包括topic的增删改查.其中kafka-topics.sh负责topic的创建与删除:kafka-configs.sh脚本负责topic的修改和查询,但 ...