By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

How to scroll a multiline System.windows.forms.textbox down to the last line through code?

P: n/a
Rvo
I have a userform which contains a textbox (System.Windows.forms.textbox)
with multiline set to True. This box contains a certain number of characters
which reach below the bottom of the box. During runtime of my program I add
text at the end of the contents of the textbox. I want to display the last
lines of the box at all times.
However, the textbox always displays the first x characters.

Can I scroll down to the end of the content of the textbox after each
addition of text to the box?

Kind regards,

Romain
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
TextBox1.Text += "Test the quick brown fox" & vbCrLf

TextBox1.Select(TextBox1.Text.Length - 1, 0)

TextBox1.ScrollToCaret()
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Rvo" <romainvoes@{DoesNotLikeSpam}vlaamsparlement.be> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I have a userform which contains a textbox (System.Windows.forms.textbox)
with multiline set to True. This box contains a certain number of characters which reach below the bottom of the box. During runtime of my program I add text at the end of the contents of the textbox. I want to display the last
lines of the box at all times.
However, the textbox always displays the first x characters.

Can I scroll down to the end of the content of the textbox after each
addition of text to the box?

Kind regards,

Romain

Nov 20 '05 #2

P: n/a
Rvo
Thanks a lot One Handed Man,

Does it nicely.

Romain
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> schreef in
bericht news:eN**************@TK2MSFTNGP09.phx.gbl...
TextBox1.Text += "Test the quick brown fox" & vbCrLf

TextBox1.Select(TextBox1.Text.Length - 1, 0)

TextBox1.ScrollToCaret()
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Rvo" <romainvoes@{DoesNotLikeSpam}vlaamsparlement.be> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
I have a userform which contains a textbox (System.Windows.forms.textbox) with multiline set to True. This box contains a certain number of

characters
which reach below the bottom of the box. During runtime of my program I

add
text at the end of the contents of the textbox. I want to display the last lines of the box at all times.
However, the textbox always displays the first x characters.

Can I scroll down to the end of the content of the textbox after each
addition of text to the box?

Kind regards,

Romain


Nov 20 '05 #3

P: n/a
* "Rvo" <romainvoes@{DoesNotLikeSpam}vlaamsparlement.be> scripsit:
Can I scroll down to the end of the content of the textbox after each
addition of text to the box?


My FAQ:

When using a RichTextBox control for displaying logging information, it is
useful to scroll the recently added line into view. There are two ways to
accomplish this:

\\\
Private Const WM_VSCROLL As Int32 = &H115
Private Const SB_BOTTOM As Int32 = 7

Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

Private Sub AddLine(ByVal Destination As RichTextBox, ByVal Text As String)
With Destination
.AppendText(Text & ControlChars.NewLine)
SendMessage(Destination.Handle, WM_VSCROLL, SB_BOTTOM, 0)
End With
End Sub
///

- or -

\\\
Dim ctr As Control = Me.ActiveControl
With Me.RichTextBox1
.Focus()
.AppendText("Hello World!")
.ScrollToCaret()
End With
ctr.Focus()
///

The 2nd solution has a side-effect: Setting the focus to the
RichTextBox control may raise validation events.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.