Advertisement
Levi0227

Átlagsebesség - Windows Form Application

Nov 16th, 2022 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | Source Code | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace atlagsebesseg
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         double time, speed, distance, meter, sec, mets;
  16.      
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void button1_Click(object sender, EventArgs e)
  23.         {
  24.             if (v.Text == "" && s.Text != "" && t.Text != "")
  25.             {
  26.                 v.Text = Convert.ToString(Convert.ToInt32(s.Text) / Convert.ToInt32(t.Text));
  27.             }
  28.             if (t.Text.Length == 0 && s.Text.Length != 0 && v.Text.Length != 0)
  29.             {
  30.                 t.Text = Convert.ToString(Convert.ToInt32(s.Text) / Convert.ToInt32(v.Text));
  31.             }
  32.             if (s.Text.Length == 0 && v.Text.Length != 0 && t.Text.Length != 0)
  33.             {
  34.                 s.Text = Convert.ToString(Convert.ToInt32(t.Text) * Convert.ToInt32(v.Text));
  35.             }
  36.             //if (s.Text == "" && v.Text == "" || s.Text == "" && t.Text == "" || v.Text == "" && t.Text == "")
  37.             //{
  38.             //    MessageBox.Show("Minimum 2 mezőt ki kell tölteni!");
  39.             //}
  40.  
  41.             try
  42.             {
  43.                 distance = Convert.ToDouble(v.Text);
  44.                 time = Convert.ToInt32(t.Text);
  45.                 speed = Convert.ToInt32(s.Text);
  46.             }
  47.             catch (FormatException)
  48.             {
  49.                 MessageBox.Show("Minimum 2 mezőt ki kell tölteni!");
  50.             }
  51.  
  52.             meter = (speed / time) / 1000;
  53.             sec = (speed / distance) * 3600;
  54.             mets = (distance * time) * 0.27777777777778;
  55.  
  56.             label6.Text = Convert.ToString(meter)+" m";
  57.             label8.Text = Convert.ToString(sec)+" s";
  58.             label10.Text = Convert.ToString(mets)+" m/s";
  59.         }
  60.  
  61.         private void button2_Click(object sender, EventArgs e)
  62.         {
  63.             v.Text = s.Text = t.Text = "";
  64.             label6.Text = " m";
  65.             label8.Text = " s";
  66.             label10.Text = " m/s";
  67.         }
  68.  
  69.         private void button3_Click(object sender, EventArgs e)
  70.         {
  71.             this.Close();
  72.         }
  73.     }
  74. }
Tags: help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement