ScrollToCaret() or scroll text in text box

Hello,

I'm working an example application the displays folder activity in a text box. How can I have to text scroll as its being entered?
I think something like ScrollToCaret() is what I may need, but not sure how to add it.

Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
        If e.ChangeType = WatcherChangeTypes.Changed Then
            txt_folderactivity.Text &= "File " & e.FullPath & " has been modified" & vbCrLf
        End If
        If e.ChangeType = WatcherChangeTypes.Created Then
            txt_folderactivity.Text &= "File " & e.FullPath & " has been created" & vbCrLf
        End If
        If e.ChangeType = WatcherChangeTypes.Deleted Then
            txt_folderactivity.Text &= "File " & e.FullPath & " has been deleted" & vbCrLf
        End If
    End Sub
LVL 8
JRockFLAsked:
Who is Participating?
 
iboutchkineConnect With a Mentor Commented:
it must work. Make sure that caret is at the end of the text

txt_folderactivity.SelectAll()
txt_folderactivity.SelectionStart = TextBox1.SelectionLength
txt_folderactivity.ScrollToCaret()

that must position th caret at the bottom of the textbox
0
 
iboutchkineCommented:
txt_folderactivity.ScrollToCaret()
0
 
JRockFLAuthor Commented:
I had tried something like this, but its not working.

 Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
        If e.ChangeType = WatcherChangeTypes.Changed Then
            txt_folderactivity.Text &= "File " & e.FullPath & " has been modified" & vbCrLf
            txt_folderactivity.ScrollToCaret()
            txt_folderactivity.Refresh()
        End If
        If e.ChangeType = WatcherChangeTypes.Created Then
            txt_folderactivity.Text &= "File " & e.FullPath & " has been created" & vbCrLf
            txt_folderactivity.ScrollToCaret()
            txt_folderactivity.Refresh()
        End If
        If e.ChangeType = WatcherChangeTypes.Deleted Then
            txt_folderactivity.Text &= "File " & e.FullPath & " has been deleted" & vbCrLf
            txt_folderactivity.ScrollToCaret()
            txt_folderactivity.Refresh()
        End If
    End Sub
0
 
JRockFLAuthor Commented:
Now that worked, thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.