PDA

Click to See Complete Forum and Search --> : Scrolling text in picturebox.


hipopony66
Oct 30th, 2001, 06:51 PM
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.

Zaei
Oct 30th, 2001, 09:48 PM
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:

image
+---------------------+
| |_text__| <- Just Blt this small area over to a memory
| | DC, and blt it back before the next
| | frame.
| |
| |
+---------------------+

Forgive the art =)


Z.

beachbum
Oct 31st, 2001, 05:35 AM
Hi
Here is a quick throw together. You can play around with the timer interval and the jump amount (ie 50)
Regards
Stuart

'FORM WITH PICTURE1, COMMAND1 AND CHECK1
'Check1 allows u to swap from horizontal to vertical
Option Explicit

Dim MyString As String
Dim MyDimension As Integer
Dim myPosn As Single
Dim MyDirection As Integer

Private Sub Form_Load()
MyString = "This is scrolling text"
Timer1.Interval = 100
Picture1.AutoRedraw = True
End Sub

Private Sub Command1_Click()
With Picture1
MyDirection = Check1.Value
myPosn = .Width * (1 - MyDirection) + .Height * MyDirection
MyDimension = .TextWidth(MyString) * (1 - MyDirection) + .TextHeight(MyString) * MyDirection
Timer1.Enabled = True
End With
End Sub

Private Sub Timer1_Timer()
With Picture1
.Cls
.CurrentX = myPosn * (1 - MyDirection)
.CurrentY = myPosn * MyDirection
Picture1.Print MyString;
myPosn = myPosn - 50
If myPosn < 0 Then
.CurrentX = (.Width + myPosn) * (1 - MyDirection)
.CurrentY = (.Height + myPosn) * MyDirection
Picture1.Print MyString;
If myPosn < -MyDimension Then myPosn = (.Width + myPosn) * (1 - MyDirection) + (.Height + myPosn) * MyDirection
End If
End With
End Sub