代码如下:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim r As New StreamReader(Application.StartupPath &"\ABC.txt", System.Text.Encoding.Default) '用StreamReader打开文本文件
Dim s As String
TextBox1.Text = ""
Do While r.Peek >-1 '是否到文件尾
s = r.ReadLine '从打开的文件中读取一行内容
TextBox1.Text = TextBox1.Text &s &vbCrLf '添加到文本框TextBox1.Text的后面并回车
Loop
r.Close() '关闭对象
End Sub
End Class
比如说用Richtext控件Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim file As String = "f:/x.txt"
RichTextBox1.LoadFile(file)
MsgBox("ok")
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)