简体   繁体   中英

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.

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. 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. 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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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