Ok, so i'm trying to get back into the swing of C# and it's slowly coming back to me but I have a slight problem. I'm making a simple stop watch program that is supposed to print the time as it ticks in a windows form app. It's as simple as:
It doesn't quite update the label as the stopwatch counts though. I can do it in as a CMD line app but I didn't want to do the application in cmd line form. Any suggestions?Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Threading; namespace WindowsFormsApplication1 { public partial class Form1 : Form { Stopwatch stopWatch = new Stopwatch(); public Form1() { InitializeComponent(); } private void start_Click(object sender, EventArgs e) { stopWatch.Start(); } private void stop_Click(object sender, EventArgs e) { stopWatch.Stop(); timePrint(); } private void reset_Click(object sender, EventArgs e) { stopWatch = Stopwatch.StartNew(); } private void timePrint() { label1.Text = stopWatch.ElapsedTicks.ToString(); hours.Text = "Time elapsed: " + stopWatch.Elapsed; } } }




Reply With Quote