Vb.net 如何用txt逐行填充富文本框?vb

Vb.net 如何用txt逐行填充富文本框?vb,vb.net,richtextbox,Vb.net,Richtextbox,我正在尝试用txt文件逐行填充富文本框。。。没有结果 这是您希望得到的结果: 房子2。狗3。第四类。等 每一个都排在另一个下面 任何帮助都会很好! 提前谢谢你 很简单,兄弟: Private Sub FillRichTextBoxFromFile(ByVal path As String) Try If IO.File.Exists(path) Then Using sr As New IO.StreamReader(pat

我正在尝试用txt文件逐行填充富文本框。。。没有结果

这是您希望得到的结果:

  • 房子2。狗3。第四类。等
  • 每一个都排在另一个下面

    任何帮助都会很好!
    提前谢谢你

    很简单,兄弟:

    Private Sub FillRichTextBoxFromFile(ByVal path As String)
            Try
                If IO.File.Exists(path) Then
                    Using sr As New IO.StreamReader(path)
                        Dim s As String = ""
                        Dim i As Integer = 1
                        While Not sr.EndOfStream
                            s += CStr(i) + ". " + sr.ReadLine + vbNewLine
                            i += 1
                        End While
                        RichTextBox1.Text = s
                    End Using
                Else
                    MsgBox("Oooops, File not found !!!")
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    

    很简单,兄弟:

    Private Sub FillRichTextBoxFromFile(ByVal path As String)
            Try
                If IO.File.Exists(path) Then
                    Using sr As New IO.StreamReader(path)
                        Dim s As String = ""
                        Dim i As Integer = 1
                        While Not sr.EndOfStream
                            s += CStr(i) + ". " + sr.ReadLine + vbNewLine
                            i += 1
                        End While
                        RichTextBox1.Text = s
                    End Using
                Else
                    MsgBox("Oooops, File not found !!!")
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    

    你也可以试试这个

        Dim fileContents() As String
    
        If Not My.Computer.FileSystem.FileExists("C:\New.txt") Then
    
            MsgBox("File Not Found")
            Exit Sub
    
        End If
    
        RichTextBox1.Text = vbNullString
    
        fileContents = Split(My.Computer.FileSystem.ReadAllText("C:\New.txt"), vbNewLine)
    
        For i = 0 To fileContents.Count - 1
    
            RichTextBox1.Text += i + 1 & ". " & fileContents(i) & vbNewLine
    
        Next
    

    你也可以试试这个

        Dim fileContents() As String
    
        If Not My.Computer.FileSystem.FileExists("C:\New.txt") Then
    
            MsgBox("File Not Found")
            Exit Sub
    
        End If
    
        RichTextBox1.Text = vbNullString
    
        fileContents = Split(My.Computer.FileSystem.ReadAllText("C:\New.txt"), vbNewLine)
    
        For i = 0 To fileContents.Count - 1
    
            RichTextBox1.Text += i + 1 & ". " & fileContents(i) & vbNewLine
    
        Next