-
July 6th, 2010, 01:24 AM
#1
Rolling text in rich text box
hi all,
I have a string in my project.
it is like "ABBNK 120 up | BXTX 66 down | CTBNK 800 down|" and so so
Here
ABBNK is Stock Name
120 is price
up is its trend
I just wanna roll this string through a richtext box (like a stock ticker) and in different color.
(green for up, red for down)
Is it possible??
-
July 6th, 2010, 01:29 AM
#2
Re: Rolling text in rich text box
RTB's don't scroll ACCROSS. This will scroll DOWN
Code:
Option Explicit
Private Declare Function SendMessage _
Lib "user32.dll" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) As Long
Private Const EM_GETFIRSTVISIBLELINE As Long = &HCE
Private Const EM_LINESCROLL As Long = &HB6
Public Sub SetTopIndex(rtb As RichTextBox, ByVal nLine As Long)
Dim nIndex As Long
nIndex = nLine - SendMessage(rtb.hwnd, EM_GETFIRSTVISIBLELINE, 0&, 0&)
Call SendMessage(rtb.hwnd, EM_LINESCROLL, 0&, ByVal nIndex)
End Sub
Private Sub Form_Load()
rtb.Text = ""
rtb.SelText = "This is a text, this is only a text test, which is long"
SetTopIndex rtb, 0
End Sub
-
July 6th, 2010, 07:54 AM
#3
Re: Rolling text in rich text box
In fact, a RichTextBox DOES scroll horizontally, too, for has it not got a horizontal scrollbar option?
But in the end I think this will not provide for the ticker effect you want.
I'd say you have to program it yourself, using a timer control which 'ticks' the text on, by deleting the first character of the vertical oriented RichTextBox and appending the next to it's end.
Coloring is a different story.
I'd do it like this:
Assumed you have a vertical rtb box, arranged like a ticker line.
First fill in as many blanks (or dots) to fill the visible field.
Then you split your original string into an array, splitting by "|"
Then you append each partial string to the rtb, coloring it depending on the occurrence of up or down.
After all strings are appended, you start the timer, which will simply always delete the first character in the rtb, thus advancing the text through the line with the time specified by the timer interval.
If you have problems to implement the algorithm like discribed, please come back for more detailed help.
-
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.
-
July 6th, 2010, 11:36 AM
#5
Re: Rolling text in rich text box
Correct me if I am wrong but it seems to me that the intention would be to continually scroll this text. In other words when it gets to the end of the data string it begins scrolling the first again.
What I would suggest is to use something similar to post number 3 but rather than delete the first character you would move the first character to the end of the string thereby creating a never ending marquee of this text though I would imagion given the content that these values would also need to be modified at some interval. What was up may be down on the next pass in some cases.
Always use [code][/code] tags when posting code.
-
July 7th, 2010, 03:01 AM
#6
Re: Rolling text in rich text box
Thanks to WoF.
I m proceeding using ur solution
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
|