【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 ...
随机推荐
- html5 移动适配写法
在pc版网页(http://pc_url) 上,添加: <link rel="alternate" media="only screen and(max-width ...
- python05 - 迭代器,生成器,装饰器
迭代器 迭代器就是访问集合元素的一种方式,迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问一遍后结束. 迭代器很大的特点: 只能往前迭代,不能够回退,也不能随机访问其中一个元素,只能通过__ ...
- ubuntu 12.04 右上角的网络连接图标突然消失不见
某天Ubuntu右上角的网络连接图标突然消失不见了,右击panel -> add to panel -> Notification Area 也不管用,最关键的是上不了网了.可以在Netw ...
- Java如何取得当前程序部署的服务器的IP
1.问题:之前使用InetAddress.getLocalHost().getHostAddress()时,在开发机测试可以得到192.168.0.18这样的IP.但部署到linux服务器以后, 这个 ...
- str_replace使用
$begintime=str_replace("-", "","2014-03-05"); (需要替换的字符串,换成字符串,需 ...
- Header的Request部分和Response部分
转载:https://zh.wikipedia.org/wiki/HTTP%E5%A4%B4%E5%AD%97%E6%AE%B5#%E8%AF%B7%E6%B1%82%E5%AD%97%E6%AE%B ...
- 取值为[1,n-1]含n个元素的整数数组,至少存在一个重复数,即可能存在多个重复数,O(n)时间内找出其中任意一个重复数,不使用额外存储空间。
有一种非常诡异的算法,就是采用类似于单链表是否存在环的问题.“判断单链表是否存在环”是一个非常经典的问题,同时单链表可以采用数组实现,此时每个元素值作为next指针指向下一个元素.本题可以转换化为“已 ...
- Linux+Redis实战教程_day03_Redis-set【重点】_有序set(了解)
2.redis-set[重点] Java HashSet 无序,不重复. Redis操作中,涉及到两个大数据集合的并集,交集,差集运算. 赋值: l sadd key values[value1.v ...
- GoF--适配器设计模式
1.概念: 适配器模式(Adapter Pattern)把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口不匹配而无法在一起工作的两个类能够在一起工作. 2.形式 a.类的适配器模式 ...
- Centos6.3 下使用 Tomcat-6.0.43 非root用户 jsvc模式部署 生产环境 端口80 vsftp
一.安装JDK环境 方法一. 官方下载链接 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260 ...