c#简易计算器
简单C#窗体程序。重量换算
编写时犯了个小错误:不能用textbox事件中的textBox_TextChanged给每个textbox换算和填充文本框。有冲突, 改变一个其他都会改变。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
    public partial class Form1 : Form
    {
        float kg, g, jin, gjin;
        public Form1()
        {
            InitializComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            kg = float.Parse(textBox1.Text);
            g = kg * 1000;
            jin = g / 500;
            gjin = jin / 2;
            textBox2.Text = g.ToString();
            textBox3.Text = jin.ToString();
            textBox4.Text = gjin.ToString();

           
        }
    }
}

avatar