zoukankan      html  css  js  c++  java
  • 计算器

                bool a; //判断上一次按键是加减乘除还是数字
                string c = ""; //判断加减乘除操作
                decimal f;//记录第一个值以及接收运算结果
                /// <summary>
                /// 数字按键
                /// </summary>
                /// <param name="sender"></param>
                /// <param name="e"></param>
                private void button1_Click(object sender, EventArgs e)
                {
                    Button b = sender as Button;
                    if (textBox2.Text == "0" || a == false)
                    {
                        textBox2.Text = b.Text;
                    }
                    else
                    {
                        textBox2.Text += b.Text;
                    }
                    if (textBox1.Text == "")
                    {
                        f = Convert.ToDecimal(textBox2.Text);
                    }
                    a = true;
                }
                /// <summary>
                /// 加减乘除
                /// </summary>
                /// <param name="sender"></param>
                /// <param name="e"></param>
                private void button4_Click(object sender, EventArgs e)
                {
                    Button b = sender as Button;
                    if (textBox2.Text.LastIndexOf(".") == (textBox2.Text.Length - 1))
                    {
                        textBox2.Text = textBox2.Text.Substring(0, (textBox2.Text.Length - 1));
                    }           
                    if (a == false)
                    {
                        textBox1.Text = textBox1.Text.Substring(0, (textBox1.Text.Length - 1)) + b.Text;
                    }
                    else
                    {
                        textBox1.Text += textBox2.Text + b.Text;
                        if (c == "1")
                        {
                            f = f + Convert.ToDecimal(textBox2.Text);
                        }
                        else if (c == "2")
                        {
                            f = f - Convert.ToDecimal(textBox2.Text);
                        }
                        else if (c == "3")
                        {
                            f = f * Convert.ToDecimal(textBox2.Text);
                        }
                        else if (c == "4")
                        {
                            f = f / Convert.ToDecimal(textBox2.Text);
                        }
                        textBox2.Text = f.ToString();
                    }
                    if (b.Text == "+")
                    {
                        c = "1";
                    }
                    else if (b.Text == "-")
                    {
                        c = "2";
                    }
                    else if (b.Text == "*")
                    {
                        c = "3";
                    }
                    else if (b.Text == "/")
                    {
                        c = "4";
                    }
                    a = false;
                }
                /// <summary>
                ///
                /// </summary>
                /// <param name="sender"></param>
                /// <param name="e"></param>
                private void button17_Click(object sender, EventArgs e)
                {
                    if (textBox2.Text.Contains(".") == false)
                    {
                        textBox2.Text += ".";
                    }
                }
                /// <summary>
                /// 等于
                /// </summary>
                /// <param name="sender"></param>
                /// <param name="e"></param>
                private void button15_Click(object sender, EventArgs e)
                {
                    if (textBox2.Text.LastIndexOf(".") == (textBox2.Text.Length - 1))
                    {
                        textBox2.Text = textBox2.Text.Substring(0, (textBox2.Text.Length - 1));
                    }
                    if (c == "1")
                    {
                        f = f + Convert.ToDecimal(textBox2.Text);
                    }
                    else if (c == "2")
                    {
                        f = f - Convert.ToDecimal(textBox2.Text);
                    }
                    else if (c == "3")
                    {
                        f = f * Convert.ToDecimal(textBox2.Text);
                    }
                    else if (c == "4")
                    {
                        f = f / Convert.ToDecimal(textBox2.Text);
                    }
                    textBox1.Text = "";
                    textBox2.Text = f.ToString();
                }
                /// <summary>
                /// 清空
                /// </summary>
                /// <param name="sender"></param>
                /// <param name="e"></param>
                private void button14_Click(object sender, EventArgs e)
                {
                    textBox1.Text = "";
                    textBox2.Text = "0";
                    a = true;
                    c = "";
                }
  • 相关阅读:
    BZOJ 4873 [Shoi2017]寿司餐厅 | 网络流 最大权闭合子图
    BZOJ 1412 [ZJOI2009]狼和羊的故事 | 网络流
    BZOJ 2242 [SDOI2011]计算器 | BSGS
    BZOJ 2480 && 3239 && 2995 高次不定方程(高次同余方程)
    用JS制作博客页面背景随滚动渐变的效果
    BZOJ 3876 支线剧情 | 有下界费用流
    ZOJ 1314 Reactor Cooling | 上下界无源汇可行流
    BZOJ 百题纪念!
    BZOJ 3238 [Ahoi2013] 差异 | 后缀数组 单调栈
    BZOJ 4417 [Shoi2013]超级跳马
  • 原文地址:https://www.cnblogs.com/zyg316/p/5628542.html
Copyright © 2011-2022 走看看