Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to force TextBox scrollbar to bottom

0 views
Skip to first unread message

John Grandy

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
if i append text to existing in a TextBox

TextBox1 = TextBox1 & NewText

the scroll bar reverts to the upper-most position

how to keep the scroll bar in its previous location ?

how to force scroll bar to bottom position ?

SOOPRcow

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
>how to force scroll bar to bottom

Text1.Selstart = Len(Text1.text)

- David Serrano
http://www.delos.net/btmsoftware/
"It's Great To Be Alive, Have a Wonderful day"

she...@rogersfoods.com

unread,
Dec 3, 1998, 3:00:00 AM12/3/98
to
In article <O2ADMTjH#GA....@uppssnewspub04.moswest.msn.net>,

"John Grandy" <JohnA...@csi.com> wrote:
> if i append text to existing in a TextBox
>
> TextBox1 = TextBox1 & NewText
>
> the scroll bar reverts to the upper-most position
>
> how to keep the scroll bar in its previous location ?
>
> how to force scroll bar to bottom position ?

Forcing the textbox to stay at the bottom is easy, just do something like:

Private Sub Text1_Change()
Text1.SelStart = Len(Text1.Text)

End Sub

Getting the textbox to maintain the same position is also fairly simple, but
requires a couple more lines of code:

'in the general declarations
Option Explicit
Dim TxtPos As Integer

'I'm using a command button to simulate the event that adds text to the
'textbox, but you can place this code in whatever event you like
Private Sub Command1_Click()
TxtPos = Text1.SelStart
Text1.Text = Text1.Text & "Hello"
Text1.SetFocus

End Sub

Private Sub Text1_Change()
Text1.SelStart = TxtPos

End Sub

Hope this helps.... :)

--
Sheppe Pharis
VB5/ActiveX Developer
http://www.riot.bc.ca/2mVB

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

qqq

unread,
Dec 3, 1998, 3:00:00 AM12/3/98
to
When you use the code:

Text1.Text = Text1.Text & "Hello"
you usually get an irritating flicker (textbox and scrollbar). This happens
as a result of assigning the ".Text" property of the textbox to a value (it
automatically sets the textbox to view the top of the text).

To help prevent this, I use the following code:
With Text1
.SelStart = len(Text1.Text) ' move to end of text
.SelText = "Hello" ' This will add the text at the
current position (i.e. the end of the box)
.SelStart = len(Text1.Text) ' or previous position if so required.
End With

This code doesn't cause the textbox to move back up to the top of the text.

Roger Bucks


she...@rogersfoods.com wrote in message <746gof$7bn$1...@nnrp1.dejanews.com>...

0 new messages