Smooth Scrolling Text

I am trying to create a right-to-left text scroller similar to the news tickers found on TV channels like Sky News, etc.

The scrolling effect needs to be as smooth as possible (i.e. as close to broadcast quality as possible). It is feasable that a lot of CPU power can be used to process the scrolling if needbe.

I have investigated various examples using Hires (multimedia?) timers which seem to be the most sucessful, but the problem i have is that the text flickers and the scrolling is not smooth, especially ones which make use of moving labels.

Can somebody suggest some code which will render the scrolling effect with as little flicker as possible.

The text will be in Arial font, at least size 48
Stuart LandrethAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Stuart LandrethAuthor Commented:
Supplemental to above, I already have code for a timer, which is firing (e.g.) every 20 milliseconds, so all I need is the text rendering code. Cheers.
0
Shahid ThaikaSole ProprietorCommented:
Flickering may not neccessarily depend on the speed of the computer. It also depends on how you have written your code. You can have your text in a Label control with autosize property set to true and then can reduce the .Left property to simulate a text-scrolling. But if you do this, then you are sure to get flickering problems. Before I remember using the BitBlt API to draw many images on the form. I used to get lots of flickering problem. I solved this problem with using a time tested solution by using BitBlt on a buffer (Maybe a picturebox control). All the image copying and text coloring would be done to this buffer and the changes would not be seen due to it being invisible. Once the processing is over, I would simple copy the buffer to the form and voila, the flickering is gone. Maybe you could try this method.

Hope this answers your question :)
0
Stuart LandrethAuthor Commented:
I managed to find this on an example

   Dim hRgn&
         
          '// print the text to the user control
          '// using paths
          With UserControl
            'open a path bracket
            BeginPath .hdc
            'draw the text
            TextOut .hdc, m_x&, 0, m_text$, Len(m_text$)
            'close the path bracket
            EndPath .hdc
            'convert the path to a region
            hRgn = PathToRegion(.hdc)
            'set the Window-region
            SetWindowRgn .hWnd, hRgn, True
            'destroy our region
            DeleteObject hRgn
         End With


which seems to use paths and regions, but still flickers a bit.

Can you give me an example of using BitBlt API as I am not not familiar with it. Thanks,.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Shahid ThaikaSole ProprietorCommented:
Please give me some time, I'll work on it.
0
Shahid ThaikaSole ProprietorCommented:
Ok I got something that works without flickering, but may not be like the cool one's that you see on tv. One a new executable project, add a timer (Timer1) and a picture box control (Picture1). Then set the following properties.

Form (Form1):
ScaleMode: 3 - Pixel

Timer (Timer1):
Interval: 50

Picture control (Picture1):
ScaleMode: 3 - Pixel
Height: 30
AutoRedraw: True
Visible: False
Appearance: 0 - Flat
BorderStyle: 0 - None




Finally copy and paste the following code...
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Sub Form_Load()
'this sizes the picture box control according to our need
setPicSize "President George W. Bush has been re-elected in the USA elections"
End Sub

Private Sub setPicSize(strText As String)
'resize the control according to the size of the text
Picture1.Width = Picture1.TextWidth(strText) + 3
'set the starting point of the text to be printed
Picture1.CurrentX = 1
Picture1.CurrentY = (Picture1.Height - Picture1.TextHeight("*")) * 0.5
Picture1.Print strText
End Sub

Private Sub Timer1_Timer()
'variable to see how much from the left should we print
Static pX As Integer

'this copies the image from one place to another
Me.Cls
BitBlt Me.hDC, 0, Me.ScaleHeight - 30, Me.ScaleWidth, 30, Picture1.hDC, pX, 0, vbSrcCopy
pX = pX + 1
If pX > Picture1.Width Then pX = 10
End Sub
0
Shahid ThaikaSole ProprietorCommented:
Oops, just found a mistake. In the second last line, the statement should be 'If pX > Picture1.Width Then pX = 0'

I would suggest you look up tutorials on BitBlt. There is a lot that you can do with it. :)
0
Stuart LandrethAuthor Commented:
I appreciate the effort you have gone to with this code, but in-line with the size i need the scroller to be...

if you change the font in the picturebox to 48, perhaps white on black background and change

BitBlt Me.hDC, 0, Me.ScaleHeight - 30, Me.ScaleWidth, 30, Picture1.hDC, pX, 0, vbSrcCopy
to
BitBlt Me.hDC, 0, Me.ScaleHeight - 100, Me.ScaleWidth, 100,Picture1.hDC, pX, 0, vbSrcCopy

it flickers like mad!

any suggestions?
0
Stuart LandrethAuthor Commented:
Aha - set the Form's Auto-Redraw to True and it seems to stop the flicker!!!
0
Shahid ThaikaSole ProprietorCommented:
Firstly, in order to get white text on black background, just change the foreground property of the picture box to 'white' and 'backcolor' to 'black'

I changed the font property of the picture control to 'Arial (Bold), size 48'. I changed the height to 74

Finally, the flickering is not because of the BitBlt API. But maybe because of the Me.Cls statement. In order to correct this, I have removed the Me.Cls line and modified the line which resizes the picture control.


NEW CODE:




Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Sub Form_Load()
'this sizes the picture box control according to our need
setPicSize "President George W. Bush has been re-elected in the USA elections"
End Sub

Private Sub setPicSize(strText As String)
'resize the control according to the size of the text
Picture1.Width = Picture1.TextWidth(strText) + Me.ScaleWidth
'set the starting point of the text to be printed
Picture1.CurrentX = 1
Picture1.CurrentY = (Picture1.Height - Picture1.TextHeight("*")) * 0.5
Picture1.Print strText
End Sub

Private Sub Timer1_Timer()
'variable to see how much from the left should we print
Static pX As Integer

'this copies the image from one place to another
BitBlt Me.hDC, 0, Me.ScaleHeight - 74, Me.ScaleWidth, 74, Picture1.hDC, pX, 0, vbSrcCopy
pX = pX + 1
If pX > Picture1.Width Then pX = 0
End Sub



I am sure this will solve your problem :)
0
Shahid ThaikaSole ProprietorCommented:
Setting the forms AutoRedraw property may have solved the problem. But depending on your software, it may not be desirable.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stuart LandrethAuthor Commented:
Thanks!!!!!

I have now sucesfully integrated this with the hi-res timer code and have a very nicely smooth scrolling text scroller!

0
Shahid ThaikaSole ProprietorCommented:
Best of Luck for your project :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.