| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 492 人关注过本帖
标题:自己写的计算器,请大家给点意见
只看楼主 加入收藏
云少
Rank: 1
等 级:新手上路
帖 子:5
专家分:3
注 册:2010-10-16
收藏
 问题点数:0 回复次数:0 
自己写的计算器,请大家给点意见

using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JSQ
{
    public partial class Form1 : Form
    {

        private string _op;//运算符
        private float _result;//数字
        
        private bool _setop = false;//是否按下运算符
        public Form1()
        {
            InitializeComponent();
        }
        //数字键
        private void btn0_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            if (_setop || this.textBox1.Text == "0" && this.textBox1.Text.Length == 1)
                this.textBox1.Clear();
            Button but = (Button)sender;
            this.textBox1.Text += but.Text;
            _setop = false;
        }
       //小数点
        private void btnspot_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Length > 0 && this.textBox1.Text.IndexOf(".") == -1)
                this.textBox1.Text += ".";
        }
        //清空
        private void btnclean_Click(object sender, EventArgs e)
        {
            this.textBox1.Clear();
        }
        //退格
        private void btn10_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Length > 1)
                this.textBox1.Text = this.textBox1.Text.Remove(this.textBox1.Text.Length - 1);
            else
                this.textBox1.Text = "0";
        }
        //运算符
        private void btnadd_Click(object sender, EventArgs e)
        {
            Calculate();
            _result =float.Parse( this.textBox1.Text);
            Button btn=(Button)sender;
            _op =btn.Text;
            _setop = true;
        }

        //运算
        private void Calculate()
        {

            float f1 = float.Parse(this.textBox1.Text);
            switch (_op)
            {
                case "+":
                    _result = _result + f1;
                    //this.textBox1.Text = (_result + f1).ToString();
                    break;
                case "-":
                    //this.textBox1.Text = (_result + f1).ToString();
                    _result = _result - f1;
                    break;
                case "*":
                    //this.textBox1.Text = (_result + f1).ToString();
                    _result = _result * f1;
                    break;
                case "/":
                    //this.textBox1.Text = (_result + f1).ToString();
                    _result = _result * 1.0f / f1;
                    break;
                case null:
                    _result = f1;
                    break;

            }
            this.textBox1.Text = _result.ToString();
        }
        //等于
        private void btnamount_Click(object sender, EventArgs e)
        {
            Calculate();
             _op=null;
            _setop=false;
        }
      
    }
}
搜索更多相关主题的帖子: 计算器 意见 
2010-10-16 19:21
快速回复:自己写的计算器,请大家给点意见
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024870 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved