Tag Archives: Scroll

Textbox Scroll with Cursor to the Top or Bottom with VB and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 3.36 out of 5)
 

I originally made this post for VB 6.0, but I figured I would go ahead and add the .NET code here as well. The first codes is for VB 6.0 and the code after is for Visual Basic.NET , VB 2005/2008, VB 2010, and newer.


Visual Basic 6.0

This will scroll to the bottom of the textbox control.

'
Text1.SelStart = Len(Text1.Text)

 

The code below will put the cursor to the beginning of the textbox and scroll to its position.

'
'Goto the top/first character in the textbox control.
TextBox1.SelStart = 0

Visual Basic.NET 2002/2003, and VB.NET 2005, 2008, 2010

This will put the cursor position at the bottom and scroll the textbox to the end of its contents.

'
'Set the cursor to the end of the textbox.
Textbox1.SelectionStart = Textbox1.TextLength
'
'Scroll down to the cursor position.
Textbox1.ScrollToCaret()

 

The codes below will set the cursor and scroll the textbox to the top or beginning of its contents.

'
'Set the cursor to the first character in the textbox which will be at the top of the control.
TextBox1.SelectionStart = 0
'
'Make the textbox scroll to the actually caret postition.
TextBox1.ScrollToCaret()

Minor Revision: 2015