How do I programatically scroll a RichTextBox to the end of it's contents ?

Re: Scroll RichTextBox by hirf-spam-me-here

hirf-spam-me-here
Mon Aug 09 05:22:01 CDT 2004

* "JezB" <jezbroadsword@blueyonder.co.uk> scripsit:
> How do I programatically scroll a RichTextBox to the end of it's contents ?

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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Re: Scroll RichTextBox by Etienne

Etienne
Mon Aug 09 22:37:42 CDT 2004

Setting the selection to the end of RichTextBox with the hide selection
property to false does the job to some point.

Etienne Boucher

"JezB" <jezbroadsword@blueyonder.co.uk> a écrit dans le message de
news:%23Fpiwm6eEHA.1604@TK2MSFTNGP11.phx.gbl...
> How do I programatically scroll a RichTextBox to the end of it's contents
?
>
>



Re: Scroll RichTextBox by hirf-spam-me-here

hirf-spam-me-here
Tue Aug 10 06:20:10 CDT 2004

* "Etienne Boucher" <etienne@novat.qc.ca> scripsit:
> Setting the selection to the end of RichTextBox with the hide selection
> property to false does the job to some point.

... only if the richtextbox has the focus.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>