Click to See Complete Forum and Search --> : Richtextbox : how to avoid scrolling
Laurent VOISIN
September 6th, 2001, 08:13 AM
Hi All,
I have a big problem that I can reproduce in the following source (the ScrollBars properties must be equal to rtfVertical before start).
My question is :
How to avoid the scrolling ?
I would like the scrollBar to rest at the bottom position when I add some text.
thank you very much,
alouillet.
private Sub Form_Load()
Dim i as Integer
me.Show
RichTextBox1.Text = ""
' Must be in the properties :
'RichTextBox1.ScrollBars = rtfVertical ' read only
for i = 0 to 200
RichTextBox1.Text = RichTextBox1.Text + "My text " + Str(i) + vbCrLf
RichTextBox1.Refresh
RichTextBox1.SelStart = len(RichTextBox1.Text) - 1
next
End Sub
Cakkie
September 6th, 2001, 08:27 AM
I'm not sure what exactly you mean, but if it is the fact that you can see the scrollbar grow smaller and smaller (that is, the block in the scrollbar), you can use this code.
strText = ""
for i = 0 to 200
strText = strText + "My text " + Str(i) + vbCrLf
next
RichTextBox1.Text = strText
RichTextBox1.SelStart = len(RichTextBox1.Text) - 1
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Laurent VOISIN
September 6th, 2001, 09:57 AM
Hi,
I anderstand what you mean but this program is just to reproduce the problem, in the reality the text arrive in an Socket_DataArrival at any time like that :
private Sub MySocket_DataArrival(byval bytesTotal as Long)
Dim strData as string
Sock_CLASS.GetData strData
RichTextBox1.Text = RichTextBox1.Text + strData
RichTextBox1.SelStart = len(RichTextBox1.Text) - 1
End Sub
So I search a tip to prevent the text cursor going at the top.
thank for response.
Laurent.
PS : Sorry for my english, I'm french...;-)
John G Duffy
September 6th, 2001, 04:19 PM
The .SelStart method should position the cursor any place within the RTB you chose. As an aside, If you wish to append text to a RichtextBox, or any control for that matter, it is usually quicker to use sendKeys then concatenating like your sample does
Richtextbox1.Text = RichtextBox1.Text + additionalText is very inefficient. Use this instead
private Sub Command1_Click()' append new text
RTB.SelStart = len(RTB.Text)
RTB.SetFocus ' Important
SendKeys vbCrLf & Text1.Text, true
End Sub
You can set .SelStart to any position within the RTB and that is where SendKeys will insert your new text.
As another aside, using the + sign to concatenate sometimes will produce undesired results. Ir your RichTextBox contains data that can be recognized as numeric and you are trying to append data that appears numeric, then VB will add them together not concatenate them.
EG.
RichTextBox1.Text = "12345"
NewText = 25
RichtextBox1 = RichtextBox1 + NewText
will result in Richtextbox1 = 12370
To Concatenate them use the Concatenation symbol & (ampersand) like so
RichTextBox1 = RichTextBox1 & NewText
This will yield
1234525
John G
Laurent VOISIN
September 7th, 2001, 04:57 AM
Hi john,
Great, it is exactly what I search.
However, I 'm not agree with you, I have a lot a data who transit and this method is less efficient (in term of rapidity) that .text=.text + "mytext".
( 4 seconds with the .Text method 13 seconds with the SendKeys method)
Secondly, I have to SendKeys to a Form that have a Modal form in front of. So I can't make the RTB.SetFocus. Have you any solution ? (e.g. sendKeys to the hwnd of the RTB) or another method to append data to the RTB.
Thank you very much for help.
Laurent VOISIN.
Laurent VOISIN
September 11th, 2001, 03:19 AM
Hi,
I found a very simple response to my question :
RTB.Selstart = Len(RTB.Text)
RTB.SelLength = 0
RTB.SelText = "My Text"
Thanks for responses.
Laurent.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.