Smooth text scrolling in C?

I have tried to do it and I've got some good news and some bad news The good news is that it is possible. I am testing the code right now and I can achieve absolutely silky smooth text scrolling even with GDI The tough part is that there are quite a few things you must ensure / implement to have it: Set DoubleBuffered to true on your rendering surface (e.g. Your form) You have to draw the text yourself, the Label class will not do (see next point as to why) You need floating point resolution in your drawing (positioning) code, which means you must use TextRenderingAntiAlias in your DrawString() calls and bigger font sizes (>10-12 pt) to make it look good You need a very high resolution timer component. I am using a component based on Win32 multimedia timers in winmm.

Dll that allows for timer event rates up to 1000 Hz and almost absolute accuracy (standard deviation below 0.1 ms). Google for MultimediaTimer component.(BTW, I know it is no longer the solution recommended by MS, but it works perfectly even in Windows 7.) Also, the Windows multimedia timer has a millisecond resolution, which cannot give you perfect 60 Hz refresh (1000/60 is not an integer), so you will need to implement some kind of a floating point display refresh counting mechanism to get as close to the display refresh rate as possible. Something along the lines of float tickCount = 0.0f; float tickDelta = 1000.0f / 60.0f; void mmTimer_Tick(object sender, EventArgs e) { tickCount++; if (tickCount >= tickDelta) { tickCount -= tickDelta; // scroll your text here Invalidate(); } } will do Finally, some minor tearing might happen occasionally.

This is all but inevitable, as you have no access to vertical sync video registers. Experiment with timings to eliminate tearing I honestly hope this helps. Let me know if you have any problems implementing it.

I have tried to do it and I've got some good news and some bad news. The good news is that it is possible. I am testing the code right now and I can achieve absolutely silky smooth text scrolling even with GDI+.

The tough part is that there are quite a few things you must ensure / implement to have it: Set DoubleBuffered to true on your rendering surface (e.g. Your form). You have to draw the text yourself, the Label class will not do (see next point as to why). You need floating point resolution in your drawing (positioning) code, which means you must use TextRendering AntiAlias in your DrawString() calls and bigger font sizes (>10-12 pt) to make it look good.

You need a very high resolution timer component. I am using a component based on Win32 multimedia timers in winmm. Dll that allows for timer event rates up to 1000 Hz and almost absolute accuracy (standard deviation below 0.1 ms).

Google for MultimediaTimer component.(BTW, I know it is no longer the solution recommended by MS, but it works perfectly even in Windows 7. ) Also, the Windows multimedia timer has a millisecond resolution, which cannot give you perfect 60 Hz refresh (1000/60 is not an integer), so you will need to implement some kind of a floating point display refresh counting mechanism to get as close to the display refresh rate as possible. Something along the lines of float tickCount = 0.0f; float tickDelta = 1000.0f / 60.0f; void mmTimer_Tick(object sender, EventArgs e) { tickCount++; if (tickCount >= tickDelta) { tickCount -= tickDelta; // scroll your text here Invalidate(); } } will do.

Finally, some minor tearing might happen occasionally. This is all but inevitable, as you have no access to vertical sync video registers. Experiment with timings to eliminate tearing.

I honestly hope this helps. Let me know if you have any problems implementing it.

For me it's ok if I work not with labels, but with images. I guess that I can implement your solution on sliding image? – user198003 Oct 12 '10 at 15:00 @user198003: Sure, it will work with any graphic object.

I used DrawString() in the rendering code, but any System.Drawing. Graphics method will work. Don't make the image too large, though, or you'll see more tearing regardless of the scrolling speed (remember, there is no VSync without DirectX).

– Alan Oct 12 '10 at 20:01.

I assumed that you use double buffering, because without it, your text WILL blink and won't look very nice at all. There is the issue with GDI that you probably have, and that's you moving speed isn't synced with monitor refresh rate. If you have 60Hz LCD monitor for example, you should update text position every 1000/60 ms, but if you use timer for that, you'll experience jerkiness now and then.

This would cause it to flash, instead of not being smooth enough, and could be solved by turning double buffering on. – treaschf Oct 8 '10 at 19:42 I assumed that double buffering is used - without it it would really look very very bad. – Daniel MoÅ¡mondor Oct 8 '10 at 19:45.

If you override the read-only property CreateParams on your form and add WX_COMPOSITE ( 0x2000000, I think that is composite ) to the params. This only works on XP and up, but it stops flickering where DoubleBuffer doesn't.

I am testing the code right now and I can achieve absolutely silky smooth text scrolling even with GDI+. Set DoubleBuffered to true on your rendering surface (e.g. Next point as to why). DrawString() calls and bigger font sizes (>10-12 pt) to make it look good.

Timers in winmm. Deviation below 0.1 ms).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions