以慢速移动图片框 [英] Move picture box in slow inimation

查看:66
本文介绍了以慢速移动图片框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想获得有关如何使PictureBox运动动画以显示汽车运动的帮助,我使用了计时器并重新放置了控制框,但是动画正在快速发展.

请问有人可以帮我做吗..

在此先感谢.
Luay.

Hi,

I like to get help on how to animate PictureBox moving to show car movement,I used timer and relocate the control box, but the animation is moving to fast.

Would any one help me to do that please..

Thanks in Advance.
Luay.

推荐答案

避免使用计时器.而是使用单独的线程,使用System.Threading.Thread.Sleep定期更新坐标并稍有延迟,然后使用System.Windows.Forms.Control.InvokeBeginInvoke通知UI线程.要使之平滑,请使用System.DataTime.NowSystem.Diagnostics.Stopwatch在每个迭代中使用实时计算坐标.

关于调用:

您无法从非UI线程调用与UI相关的任何操作.相反,您需要使用System.Windows.Threading.DispatcherInvokeBeginInvoke方法(对于Forms或WPF)或System.Windows.Forms.Control(仅对于Forms).

在我过去的答案中,您将找到有关其工作原理的详细说明和代码示例:
Control.Invoke()与Control.BeginInvoke() [ ^ ],
Treeview Scanner和MD5的问题 [如何获取keydown事件在vb.net中的不同线程上操作 [启用禁用+多线程后控件事件不会触发 [ ^ ].

现在,也许您根本不需要PictureBox.我不确定它是否对您有帮助.您可以使用自定义控件直接为事物设置动画.这是这样的:
如何从旧图纸中清除面板 [ ^ ].阅读上面提到的我过去的答案,以获取使用System.Windows.FormsSystem.Drawing进行动画制作的一般思路.

—SA
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


希望它可以帮助您解决问题,
如何在图片框内移动图像 [ ^ ]
使用C#的动画组件 [
Hope it helps solve your problem,
How To Move Around An Image In A Picturebox[^]
An Animation Component using C#[^]


这篇关于以慢速移动图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆