请大家提供一个打开文件对话框,并把文件内容读取到TextBox中的例子
RT
[解决办法]
'cdg commondialog控件
Cdg.Filter = "文本文件(*.txt|*.txt "
Cdg.FileName = " "
Cdg.ShowOpen
If Cdg.FileName <> " " Then
strOpen = Cdg.FileName '文件路径
End If
'读数据
Open strOpen For Input As #1 '打开网络中文件
TempData = StrConv(InputB$(LOF(1), 1), vbUnicode) '字符转化
LedData = TempData
Close #1 '关闭文件
[解决办法]
1.如果直接用RichTextBox可以用LoadFile 来装载文件内容,如:
RichTextBox1.LoadFile "d:\a.txt "
2.用TextBox则如:
Private Sub Command1_Click()
Dim s As String
With CommonDialog1
.Filter = "*.txt(文本文件)|*.txt "
.ShowOpen
Open .FileName For Binary As #1
s = Input$(LOF(1), #1)
Close #1
Text1.Text = s
End With
End Sub