I have a WinForms app which I'd like to have a clock in the bottom left. So far I managed to display the time when it launched, but I can't make it update itself. I tried to use a BackgroundWorker but since it is on a different thread it errors out so it can't change anything.
I hope there's a somewhat easy fix to my problem
Thanks in advance!
Edit 1 would be adding some of the code
DateTime output;
Random rnd = new Random();
private void GetTime_DoWork(object sender, DoWorkEventArgs e)
{
GetTime.ReportProgress(rnd.Next(1, 62));
}
private void GetTime_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
output = DateTime.Now;
TimeLabel.Text = output.Hour + ":" + output.Minute + ":" + output.Second;
DateLabel.Text = output.ToString("yyyy-MM-dd, dddd");
}
"output" is a DateTime type variable where I'd like to store the values of the current time
The random number generator is only used to change the progress
TimeLabel only outputs time
DateLabel outputs in 2020-01-01 Wednesday
format
Edit 2: Using Timer element worked, Thread.Sleep(1000);
isn't used since it would halt everything else on the form
Adding new code:
public Form1()
{
InitializeComponent();
TimeUpdate.Start();
}
//...
private void TimeUpdate_Tick(object sender, EventArgs e)
{
output = DateTime.Now;
TimeLabel.Text = output.ToString("HH:mm:ss");
DateLabel.Text = output.ToString("yyyy-MM-dd, dddd");
}
//TimeUpdate is the name of the Timer