|
-
July 6th, 2010, 10:03 AM
#4
Re: Rolling text in rich text box
In fact, come to think of it, scrolling is easier with the scrollbar:
Put a RichTextBox named rtb on a form.
Set its .MultiLine property to false and the .Scrollbar property to rtfHorizontal
Put a Timer Timer1 on your form. Set the interval to 80
The following code fills the rtb with the ticker line, colors it and scrolls it by timer control.
Code:
Private Sub Form_Load()
Dim n%, p%
'this only fills in a dummy ticker line. Tick should contain your ticker line to show.
For n = 1 To 10: Tick = Tick + "ABBNK 120 up | BXTX 66 down | CTBNK 800 down | ": Next
'fill the rtb with a set of dots (or spaces) depending on its size, + the ticker string
rtb.Text = String(PreLen, ".") + Tick
'now do the coloring
n = PreLen + 1
Do
rtb.SelStart = n - 1
p = InStr(n, rtb.Text, "|")
If p = 0 Then p = Len(rtb.Text)
rtb.SelLength = p - n
rtb.SelColor = IIf(InStr(rtb.SelText, "up"), vbGreen, vbRed)
n = p + 1
Loop Until p >= Len(rtb.Text)
rtb.SelStart = 0
End Sub
Private Sub Timer1_Timer()
SendKeys "{right}"
End Sub
Also the timer control is rather primitive it works fine.
If necessary the timer can use SendMessage to scroll the rtb forward. Or there is maybe an even better way to emulate the right arrow key.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|