Avoid using timer. Instead, use the separate thread, update the coordinates periodically with some delay using
System.Threading.Thread.Sleep
and notify UI thread using
System.Windows.Forms.Control.Invoke
or
BeginInvoke
. To make is smooth, use real time for calculation of coordinate in each iteration using
System.DataTime.Now
or
System.Diagnostics.Stopwatch
.
About invocation:
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[
^].
Now, maybe you don't need
PictureBox
at all. I'm not sure it helps you. You can animate things directly using custom Control. This is how:
How do I clear a panel from old drawing[
^]. Read my past answer referenced above for general idea on animation using
System.Windows.Forms
with
System.Drawing
.
—SA