Skip to content

Instantly share code, notes, and snippets.

@DDeenis
Created September 2, 2022 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DDeenis/c5734925db8d575c3279076d3d709020 to your computer and use it in GitHub Desktop.
Save DDeenis/c5734925db8d575c3279076d3d709020 to your computer and use it in GitHub Desktop.
namespace MovingForm
{
public partial class Form1 : Form
{
System.Windows.Forms.Timer timer = new();
DateTime startTime;
public Form1()
{
InitializeComponent();
timer.Interval = 500;
timer.Tick += new EventHandler(TimerTick);
startTime = DateTime.Now;
timer.Start();
}
void TimerTick(object? sender, EventArgs e)
{
var distance = DateTime.Now - startTime;
int milliseconds = distance.Minutes * 60 * 1000 + distance.Seconds * 1000 + distance.Milliseconds;
Text = milliseconds.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment