2
我试图用txt文件逐行填充一个富文本框......没有结果!如何填充富文本框行按行与txt? vb
这是希望得到的结果:
- 房屋2.狗3.猫4.等
每一个在下面的其他
任何帮助的行会很好! 预先感谢您!
我试图用txt文件逐行填充一个富文本框......没有结果!如何填充富文本框行按行与txt? vb
这是希望得到的结果:
每一个在下面的其他
任何帮助的行会很好! 预先感谢您!
这是很简单的哥哥:
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