TextCursor in RichTextBox

R

Richard

When you give focus to a RichTextBox, then it goes to the textCursor, but i
don't want to give the richtextbox focus, cause there is being written a lot
in it, and I have to do something else at the same time, then if I don't
give it focus, and I add some text to it, then it don't automaticly scrolls
down to the textcursor, is there a way to make the RichTextBox scroll down
to the textcursor, without giving it focus??

Richard
 
J

Jared

Richard, I don't think that is true
Add a new form
1 place a textbox, a button and a richtextbox on the form and add the
following code.
Now, examine the output window.

My Output:
Got Focus

'My button control was pressed

Lost Focus

Got Focus

'Reset the focus to the textbox to make a point

Line Number 1

Line Number 2

Line Number 3

Line Number 4

Line Number 5

'Occurred when I incpected the output window and moved focus to the DevEnv

Lost Focus


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.TextBox1.Focus()

For counter As Integer = 1 To 5

Me.RichTextBox1.AppendText("Line Number " & counter & vbCrLf)

Console.WriteLine("Line Number " & counter)

Me.RichTextBox1.ScrollToCaret()

Next

End Sub

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.LostFocus

Console.WriteLine("Lost Focus")

End Sub

Private Sub Textbox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus

Console.WriteLine("Got Focus")

End Sub
 
H

Herfried K. Wagner [MVP]

* "Richard said:
When you give focus to a RichTextBox, then it goes to the textCursor, but i
don't want to give the richtextbox focus, cause there is being written a lot
in it, and I have to do something else at the same time, then if I don't
give it focus, and I add some text to it, then it don't automaticly scrolls
down to the textcursor, is there a way to make the RichTextBox scroll down
to the textcursor, without giving it focus??

If you want to scroll to the end of the text:

From 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
///
 
R

Richard

Thank you SO much, that was just what I was searching for.

QUOTE: "From my FAQ:"

Where Can I find your FAQ??


Yet again, thank you for the help.

Richard
 
R

Richard

Notice that the index of the FAQ is currently in German, the articles
linked by the index are written in English :).

ok, that's not the easiest to read (The german headlines), but thanks
anyway,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top