Created
September 2, 2022 07:00
-
-
Save DDeenis/c5734925db8d575c3279076d3d709020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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