🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.basic.visual.misc
Article #505

Re: RichTextBox (HowTo keep focus on bottom)

#505
From: stevesykes
Date: Wed, 14 Oct 1998 00:00
116 lines
5591 bytes
Try this,
in a module place this code:
Public Function ScrollText&(TextBox As Control, vLines As Integer)
       #If Win32 Then
       Dim Success As Long
       Dim SavedWnd As Long
       Dim r As Long
       Const EM_LINESCROLL = &HB6
       #Else
       Dim Success As Integer
       Dim SavedWnd As Integer
       Dim r As Integer
       Const EM_LINESCROLL = &H406
       #End If
       SavedWnd = Screen.ActiveForm.hwnd
       Dim z As Long
       Lines& = vLines
       ' Set the focus to the passed control (text control).
       'TextBox.SetFocus
       ' Scroll the lines.
       Success = SendMessage(TextBox.hwnd, EM_LINESCROLL, 0, Lines&)
       'r = PutFocus(SavedWnd)
       ' Return the number of lines actually scrolled.
       ScrollText& = Success
       End Function

To make the box scoll use this,
Num& = ScrollText&(frmNameBox, numlines)
numlines is the number of lines to scroll
frmNameBox is the box to scroll
This works on all types of text boxes




In article <3621515D.4C3A@hotmail.com>,
  Anonymous VB User <just_up_stairs@hotmail.com> wrote:
> 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
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
Technical Details
Message-ID: <702mic$lf8$1@nnrp1.dejanews.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6s2of7$10c$1@news0-alterdial.uu.net> <3621515D.4C3A@hotmail.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11629a,f7468dc70f59f2ab
X-Google-Attributes: gid11629a,public
X-Google-Thread: 110e3b,f7468dc70f59f2ab
X-Google-Attributes: gid110e3b,public
X-Google-Thread: 1053fc,f7468dc70f59f2ab
X-Google-Attributes: gid1053fc,public
X-Google-Thread: 1212f1,f7468dc70f59f2ab
X-Google-Attributes: gid1212f1,public
From: stevesykes@my-dejanews.com
Subject: Re: RichTextBox (HowTo keep focus on bottom)
Date: 1998/10/14
Message-ID: <702mic$lf8$1@nnrp1.dejanews.com>
X-Deja-AN: 401031825
References: <6s2of7$10c$1@news0-alterdial.uu.net> <3621515D.4C3A@hotmail.com>
X-Http-Proxy: 1.0 proxy.compaq.com, 1.0 proxy.compaq.com, 1.0 x12.dejanews.com:80 (Squid/1.1.22) for client 207.18.199.151
Organization: Deja News - The Leader in Internet Discussion
X-Article-Creation-Date: Wed Oct 14 17:21:16 1998 GMT
Newsgroups: comp.lang.basic.visual.misc,comp.lang.clipper.visual-objects,es.comp.lenguajes.visual-basic,microsoft.public.visualj.debugger
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)