简体   繁体   English

C#-如何使用微秒?

[英]C# - How do I use microseconds?

I'm trying to make a picturebox move smoothly across a winform and the only way it even looks smooth is if I use a timer and lower the pixel speed to 1 px per 1 microsecond, and even then the movement of the picturebox is slow. 我正在尝试使图片框在winform上平滑移动,并且即使看上去平滑,唯一的方法是使用计时器并将像素速度降低到每1微秒1 px,即使这样图片框的移动也很慢。

How do I use microseconds to make the picturebox move alot faster while still maintaining the level of smoothness when moving? 如何使用微秒使图片框更快地移动,同时仍保持移动时的平滑度?

First I have no idea what your asking so maybe this will help maybe not. 首先,我不知道您的要求是什么,所以这可能会有所帮助。

Timing is a tricky issue. 时间安排是一个棘手的问题。 First All of the .net timers are at the milli second resolution and below that you have no assurance what the system is returning you with out using some type high resolution timer. 首先,所有.net计时器都以毫秒为单位,低于该分辨率时,您将无法确定系统使用某种类型的高分辨率计时器将返回什么。 The .net stopwatch uses the underlying high resolution timer but does not have a call back mechanism so you will need to build that your self utilizing a different thread and polling. .net秒表使用底层的高分辨率计时器,但没有回调机制,因此您将需要使用其他线程和轮询来构建自己的自我。 That said you may want to look at animating in a different fashion then moving a picture box such as using bit blt or overloading the low level paint. 就是说,您可能希望以其他方式进行动画处理,然后再移动图片框,例如使用位blt或使低级绘画过载。

I'd imagine that moving a control across a form is a reasonably slow operation; 我以为在窗体上移动控件是一种相当缓慢的操作。 so it's not that your timer isn't fine grained enough, it's going to flicker anyway. 因此,这并不是说您的计时器不够精细,无论如何它都会闪烁。 Rather than moving a picture box, you could paint whatever you had in the picture box onto the form background in the Paint event instead, changing the position you draw it to when a timer ticks. 与其移动图片框,不如将其在框内的内容绘制到Paint事件中的窗体背景上,而是在计时器计时时更改其绘制位置。 This way you could take advantage of things like double buffering for more smooth animation. 这样,您可以利用双缓冲之类的功能获得更流畅的动画。 You'll find that even a comparatively large interval like 40ms (25Hz refresh) should be enough in this case. 您会发现在这种情况下,即使是较大的间隔(如40ms(25Hz刷新))也足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM