Article View: comp.lang.basic.visual.misc
Article #506Re: RichTextBox (HowTo keep focus on bottom)
From: Anonymous VB User
Date: Sun, 11 Oct 1998 00:00
Date: Sun, 11 Oct 1998 00:00
77 lines
4192 bytes
4192 bytes
Greetings, Bernie! I noticed your inquiry about using
a rich text box control in a chat program. I had
run into the same annoyance as you have, when writing
a chat client/server combo, noting that the Rtb control
keeps jumping up to the top of the text, when what you
want is for it to scroll down, with the latest
updates. At the time I used the following as a quick fix:
rtbOutput.UpTo stPlaceholder, True
That line tells the control to look for the placeholder,
and to move forward, from the first line of text to the
last. The placeholder was set to be a character that you could
not normally type via the keyboard, in fact, it works best when
the character never shows up in the text, that way, it scans all
the way to the bottom of the text, finds nothing, and leaves
the text view there. Not exactly what I wanted, it flickered
noticably once the text contents went off screen.
Christion's example is similiar, and I tested it out, it works,
in fact, you'll never have the character problem with that code,
but it still flickers too much for my taste.
Fortunately, Christian's code example gave me an idea, and so
far it's working real nice (it's about up to about a 1250 lines
of text), and still updating every half second. Minimal flicker,
once about every three text appends, and you can tell it's not trying
to scroll down, or up, or anything like that. (IE, it's reasonable,
even for a would-be picky user like myself)
Here it is (By the way, thanks Christian!):
rtb.SelStart = Len(rtb.Text)
rtb.SelText = "Add whatever text you want"
This neatly inserts your text into the text currently
being displayed, and exactly at the end of it, too.
No more excessive flickering due to the rtb completely
updating its display (which is exactly what it does when
you do the following: rtb.text = rtb.text & "More Text")
And it doesn't try to shift the text view back to the
top, which is the whole point of doing this, right? ;)
Translated to roughly fit your code:
Private Sub cmdAdd_Click()
Dim stUID As String
stUID = "(UserName)"
rtb1.SelStart = Len(rtb1.Text)
rtb1.SelText = vbNewLine + stUID + ":>" + rtbAdd.Text
End Sub
One more line of code, three times less flicker! What a deal!
(I've already added it my chat client/server, too. Slick!)
bernie wrote:
>
> i am building a small chat program. it looks like AOL's imstand messanger.
> it uses to rich text boxes and the bottom one sends text to the top one
> using the code below to send the text to the box on the next line. the top
> box everyone see's EX>
>
> Private Sub cmdAdd_Click()
> Dim stUID As String
> stUID = "(UserName)"
> rtb1.Text = rtb1.Text + vbNewLine + stUID + ":>" + rtbAdd.Text
>
> End Sub
>
> it works correctly but i when there is too many lines the new text can't be
> seen i have the scroll bar and you can scroll by hand but i want itto
> automaticly scroll to that last line of text.
>
> if anyone can help me with this or anything doing with building an chat
> program please post or email me at deforest@mkl.com
Technical Details
Message-ID:
<3621515D.4C3A@hotmail.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6s2of7$10c$1@news0-alterdial.uu.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1212f1,f7468dc70f59f2ab X-Google-Attributes: gid1212f1,public X-Google-Thread: 1053fc,f7468dc70f59f2ab X-Google-Attributes: gid1053fc,public X-Google-Thread: 111c14,f7468dc70f59f2ab X-Google-Attributes: gid111c14,public X-Google-Thread: 110e3b,f7468dc70f59f2ab X-Google-Attributes: gid110e3b,public X-Google-Thread: 11629a,f7468dc70f59f2ab X-Google-Attributes: gid11629a,public From: Anonymous VB User <just_up_stairs@hotmail.com> Subject: Re: RichTextBox (HowTo keep focus on bottom) Date: 1998/10/11 Message-ID: <3621515D.4C3A@hotmail.com> X-Deja-AN: 400077951 Content-Transfer-Encoding: 7bit References: <6s2of7$10c$1@news0-alterdial.uu.net> Content-Type: text/plain; charset=us-ascii X-Trace: 11 Oct 1998 20:38:31 -0500, 208.13.202.68 Organization: Together Networks - Burlington, VT. MIME-Version: 1.0 Newsgroups: comp.lang.basic.visual.misc,comp.lang.clipper.visual-objects,es.comp.lenguajes.visual-basic,microsoft.public.visualj.debugger,no.it.programmering.visual-basic