First of all, never use
System.Windows.Forms.Timer
for animation, use one of the other timers. Even better and simpler, don't use a timer, use a separate thread. If you need to know real time of the move, use
System.Diagnostics.Stopwatch
(you only need relative time). Make smaller steps.
Now, with all the timers (except the one I mentioned above which cannot give you any acceptable accuracy) and with a separate thread, you will need to delegate your method changing anything on your UI to the UI thread. You cannot call anything related to UI from non-UI thread. Instead, you need to use the method
Invoke
or
BeginInvoke
of
System.Windows.Threading.Dispatcher
(for both Forms or WPF) or
System.Windows.Forms.Control
(Forms only).
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
Write code accurately; never ever use auto-generated names like
Label4
or
Timer1_Tick
; they violate (good) Microsoft naming conventions and not indented for permanent use; rename them all to give semantically sensible names, otherwise you code will be hard to maintain.
Basically, that's all you need.
—SA