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

Automatic scroll of RichTextBox

P: n/a
Hi,

Is it possible to scroll a RichTextBox programmatically to a given text
selection in it, such that the selected text becomes viewable.

regards.
Jesper.

Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Jesper,

For this, first specify the "SelectedText" of the richtextbox control and
then call the ScrollToCaret method. Here's an example:

'Handles the Enter key being pressed while TextBox1 has focus.
Private Sub TextBox1_KeyDown(ByVal sender As Object, _
ByVal e As KeyEventArgs) Handles TextBox1.KeyDown
TextBox1.HideSelection = False
If e.KeyCode = Keys.Enter Then
e.Handled = True

' Copy the text from TextBox1 to RichTextBox1, add a CRLF after
' the copied text, and keep the caret in view.
RichTextBox1.SelectedText = TextBox1.Text + _
Microsoft.VisualBasic.vbCrLf
RichTextBox1.ScrollToCaret()
End If
End Sub

Hope this helps.
Thanks
Mona [GrapeCity]

"Jesper" <Je****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.com...
Hi,

Is it possible to scroll a RichTextBox programmatically to a given text
selection in it, such that the selected text becomes viewable.

regards.
Jesper.

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.