c#計算器

王ys發表於2024-06-28
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 計算器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        char p=' ';
        int v1=0,v2=0;
        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            p = '+';
        }
        private void button4_Click(object sender, EventArgs e)
        {
            if (p == '+')
            {
                textBox1.Text = "";
                v1 = v1 + v2;
                textBox1.Text = v1 + "";
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            if (p == ' ')
            {
                v1 = v1 * 10 + 1;
                textBox1.Text = v1 + "";
            }
            else
            {
                v2 = v2 * 10 + 1;
                textBox1.Text = v2 + "";
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (p == ' ')
            {
                v1 = v1 * 10 + 2;
                textBox1.Text = v1 + "";
            }
            else
            {
                v2 = v2 * 10 + 2;
                textBox1.Text = v2 + "";
            }
        }

        

        

        

        

        

        

        
        

        
        


        
    }
}

  

相關文章