Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

using using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Threading.Tasks; System.Windows.Forms; System.Diagnostics;

namespace StopWatch { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Stopwatch sw = new Stopwatch(); private void label1_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { if (button1.Text == "Start") { timer1.Enabled = true; sw.Start(); button1.Text = "Stop"; } else { timer1.Enabled = false; sw.Stop(); button1.Text = "Start"; } } private void timer1_Tick(object sender, EventArgs e) { int hours = sw.Elapsed.Hours; int minutes = sw.Elapsed.Minutes; int seconds = sw.Elapsed.Seconds; label1.Text = hours + ":"; if (minutes < 10) { label1.Text += "0" + minutes + ":"; } else { label1.Text +=minutes + ":"; } if(seconds < 10) { label1.Text += "0" +seconds+ ":"; } else

{ label1.Text +=seconds +":"; } } private void button2_Click(object sender, EventArgs e) { sw.Restart(); } } }

You might also like