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 WindowsFormsApp1 { public partial class Form1 : Form { DateTime start = new DateTime(); DateTime stop = new DateTime(); TimeSpan duration = new TimeSpan(); TimeSpan currSpan = new TimeSpan(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { InitTimer(); } private void button1_Click(object sender, EventArgs e) { start = DateTime.Now; timer1.Enabled = true; button1.Enabled = false; timer2.Start(); } private void button2_Click(object sender, EventArgs e) { stop = DateTime.Now; duration = stop - start; timer1.Enabled = false; button1.Enabled = true; timer2.Stop(); //Data.lasttime = currSpan.ToString(); Data.data.Add(currSpan.ToString()); label2.Text = ""; foreach (var item in Data.data) { label2.Text += $"{item}\n"; } //label2.Text = Data.lasttime; } private void label1_Click(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { textBox1.Text = DateTime.Now.ToString("HH:mm:ss:fff"); } private void textBox2_TextChanged(object sender, EventArgs e) { } private void timer2_Tick(object sender, EventArgs e) { currSpan = DateTime.Now - start; textBox2.Text = currSpan.ToString(); } public void InitTimer() { timer1 = new Timer(); timer1.Tick += new EventHandler(timer2_Tick); timer1.Interval = 10; // in miliseconds } private void label2_Click(object sender, EventArgs e) { } public static class Data { public static string lasttime = ""; public static List data = new List(); } } }