不正确的计算输出

Incorrect calculation output

我正在尝试创建一个简单的表格来计算速度、距离和行进的时间,但计算结果有误。

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 _2ndTask
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        double speed, time, distance, laiks, garums, atrums; // laiks = time2, garums = distance2, atrums = speed2

        private void label1_Click_1(object sender, EventArgs e)
        {

        }
        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            bool timeInput = double.TryParse(textBox3.Text, out laiks);
            
            if (!timeInput || laiks < 0 || laiks > 9999)
            {
                // MessageBox.Show("Ignorēt šo paziņojumu.");
            }
            // timeInput = float.Parse (textBox3.Text);
            
            
        }   


        private void textBox2_TextChanged2(object sender, EventArgs e)
        {
            
            
            bool cGarumsInput = double.TryParse(textBox2.Text, out garums);

            if (!cGarumsInput || garums < 0 || garums > 999999)
            {
                // MessageBox.Show("Ignorēt šo paziņojumu.");
            }
            

        }
        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
            
            bool speedInput = double.TryParse(textBox3.Text, out atrums);

            if (!speedInput || atrums < 0 || atrums > 9999)
            {
                // MessageBox.Show("Ignorēt šo paziņojumu.");
            
            } 
            
        }
        private void button2_Click(object sender, EventArgs e)
        {
            time = (garums / atrums);
            label4.Text = time.ToString();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            distance = atrums * laiks;
            label4.Text = distance.ToString() + " Km.";
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            speed = garums / laiks;
            label4.Text = speed.ToString() + " Km/h.";

        }
    }
}

在我添加 TryParse 之前,计算是正确的,但只要从文本框中删除值,表单就会崩溃。

下面应该输出140(乘以时间和速度)而不是输出49。输入其他数字也给出错误结果

你打错了。您正在将 textBox3 中的文本分配给 atrums 和 laiks。大概其中一个应该使用 textBox1 中的文本。