Results 1 to 7 of 7

Thread: Scrolling Text

  1. #1

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    Scrolling Text

    How can i make the text in a text box/label scroll?

  2. #2
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Put some text in a label and add the following code to a timer with interval set to 100
    VB Code:
    1. Label1.Caption = Right$(Label1.Caption, Len(Label1.Caption) - 1) & Left$(Label1.Caption, 1)

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. 'Put a Timer and a Picture Box on the form
    2. 'Set the Timer Interval to 3
    3. 'Add the following code to the Timer1_Timer event
    4.  
    5. Const MyStr = "Hello, this is a test string"
    6.  
    7. Static TopText As Integer
    8. Static TopLoaded As Boolean
    9.  
    10. Dim Speed As Integer
    11. Dim NotShowing As Long
    12.  
    13. 'speed is one pixel per tick
    14. Speed = Screen.TwipsPerPixelY
    15.  
    16. If Not TopLoaded Then
    17.     'only set this once
    18.     TopText = Picture1.ScaleHeight
    19.     TopLoaded = True
    20. End If
    21. 'clear picture box text
    22. Picture1.Cls
    23.  
    24. 'center the text about to be displayed
    25. Picture1.CurrentY = TopText
    26. Picture1.CurrentX = (Picture1.ScaleWidth \ 2) - (Picture1.TextWidth(MyStr) \ 2)
    27.  
    28. 'display text
    29. Picture1.Print MyStr
    30.  
    31. 'if text has moved past the top of the picture box
    32. 'then start scrolling text from the bottom
    33. NotShowing = (TopText + Picture1.TextHeight(MyStr))
    34. If NotShowing < 0 Then
    35.     TopText = Picture1.ScaleHeight
    36. Else
    37.     'else continue moving text up
    38.     TopText = TopText - Speed
    39. End If

  4. #4

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Thanks hack. The mega-mans example was great, don't get me wrong, but this was just what i was looking for.

  5. #5

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    is there any way of scrolling multi lined messgaes?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Sub Timer1_Timer()
    2. 'Put a Timer and a Picture Box on the form
    3. 'Set the Timer Interval to 3
    4. 'Add the following code to the Timer1_Timer event
    5.  
    6. Dim MyStr As String
    7.  
    8. MyStr = "Here is comes to save the day..." & vbCrLf
    9. MyStr = MyStr & Space(15) & "Good ole Hack is on the way.!"
    10.  
    11. Static TopText As Integer
    12. Static TopLoaded As Boolean
    13.  
    14. Dim Speed As Integer
    15. Dim NotShowing As Long
    16.  
    17. 'speed is one pixel per tick
    18. Speed = Screen.TwipsPerPixelY
    19.  
    20. If Not TopLoaded Then
    21.     'only set this once
    22.     TopText = Picture1.ScaleHeight
    23.     TopLoaded = True
    24. End If
    25. 'clear picture box text
    26. Picture1.Cls
    27.  
    28. 'center the text about to be displayed
    29. Picture1.CurrentY = TopText
    30. Picture1.CurrentX = (Picture1.ScaleWidth \ 2) - (Picture1.TextWidth(MyStr) \ 2)
    31.  
    32. 'display text
    33. Picture1.Print MyStr
    34.  
    35. 'if text has moved past the top of the picture box
    36. 'then start scrolling text from the bottom
    37. NotShowing = (TopText + Picture1.TextHeight(MyStr))
    38. If NotShowing < 0 Then
    39.     TopText = Picture1.ScaleHeight
    40. Else
    41.     'else continue moving text up
    42.     TopText = TopText - Speed
    43. End If
    44. End Sub

  7. #7

    Thread Starter
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    thanks hack

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width