Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to read the pasted text line by line in RichTextBox?

$
0
0

Hai all,

I am using a RichTextbox to read its content line by line.Here is the code I used for that:

 Private Sub txt_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.TextChangedEventArgs) Handles txt.TextChanged
        Dim line As [String]
        Dim trimmedline As String
        Dim rtbContents As String = New TextRange(txt.Document.ContentStart, txt.Document.ContentEnd).Text
        For Each line In rtbContents.Split(ControlChars.Lf)
            trimmedline = line.Trim(" c", ControlChars.Cr)
            If trimmedLine.Length > 0 Then
                lb.Content = trimmedLine.First
            End If
        Next
End Sub
It works fine when I write the text directly in the textbox but if I paste a few lines in it,the label only shows the last line.I don't know how to fix it.Can anyone please help me solve this problem?



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>