Results 1 to 3 of 3

Thread: Scrolling text in picturebox.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Scrolling text in picturebox.

    Hey, I posted this in the general forum, and did a search, but every way I've seen varies from all the others, and none really seem simple. Soooooooo, I figured some of you guys would know the simplest way to scroll text from right to left in a picturebox where it keeps coming in from the right again, after it scrolls out of the left side of the picturebox. If textout is the easiest way to do this, please let me know the API for this. Any help with this is greatly appreciated.

  2. #2
    Zaei
    Guest
    It seems that things have been pretty lax today...

    Anyway, The easiest way to do this would be to load your image into a Memory DC, then, when the text moves, BitBlt your base image from the Memory DC into the picture box, or whatever, then draw your text. This way, the text from the previous frame gets cleared by the picture being Bltted over it, and you can draw the text fresh, moved a bit to the left. Then, when the text is all the way off the image, just start it over at the right again.

    For speed considerations, you may just want to Blt the area that the text will cover to a memory DC BEFORE you draw the text on each frame, and then just Blt only the small portion covered by text over the text before the next frame:
    Code:
    image
    +---------------------+
    |             |_text__|  <-  Just Blt this small area over to a memory 
    |                     |          DC, and blt it back before the next
    |                     |          frame.
    |                     |
    |                     |
    +---------------------+
    Forgive the art =)


    Z.

  3. #3
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    Here is a quick throw together. You can play around with the timer interval and the jump amount (ie 50)
    Regards
    Stuart
    VB Code:
    1. 'FORM WITH PICTURE1, COMMAND1 AND CHECK1
    2. 'Check1 allows u to swap from horizontal to vertical
    3. Option Explicit
    4.  
    5. Dim MyString As String
    6. Dim MyDimension As Integer
    7. Dim myPosn As Single
    8. Dim MyDirection As Integer
    9.  
    10. Private Sub Form_Load()
    11.     MyString = "This is scrolling text"
    12.     Timer1.Interval = 100
    13.     Picture1.AutoRedraw = True
    14. End Sub
    15.  
    16. Private Sub Command1_Click()
    17.     With Picture1
    18.         MyDirection = Check1.Value
    19.         myPosn = .Width * (1 - MyDirection) + .Height * MyDirection
    20.         MyDimension = .TextWidth(MyString) * (1 - MyDirection) + .TextHeight(MyString) * MyDirection
    21.         Timer1.Enabled = True
    22.     End With
    23. End Sub
    24.  
    25. Private Sub Timer1_Timer()
    26.     With Picture1
    27.         .Cls
    28.         .CurrentX = myPosn * (1 - MyDirection)
    29.         .CurrentY = myPosn * MyDirection
    30.         Picture1.Print MyString;
    31.         myPosn = myPosn - 50
    32.         If myPosn < 0 Then
    33.             .CurrentX = (.Width + myPosn) * (1 - MyDirection)
    34.             .CurrentY = (.Height + myPosn) * MyDirection
    35.             Picture1.Print MyString;
    36.             If myPosn < -MyDimension Then myPosn = (.Width + myPosn) * (1 - MyDirection) + (.Height + myPosn) * MyDirection
    37.         End If
    38.     End With
    39. End Sub
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

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