VB里如何让一个文本文件的内容在TEXTBOX控件里显示
有一个TEXT1控件,如何把ABC.TXT这个文本文件拖动到TEXT1里面,让TEXT1里显示ABC.TXT里的内容?...
有一个TEXT1控件,如何把ABC.TXT这个文本文件拖动到TEXT1里面,让TEXT1里显示ABC.TXT里的内容?
展开
3个回答
展开全部
LZ要的是拖放并打开吧~试试这个吧~
text1的OLEDropMode要设为1~
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim FF As Integer
FF = FreeFile
Dim a As String
Dim b As String
Me.Caption = Data.Files.Item(1)
Open Data.Files.Item(1) For Input As #FF
Do Until EOF(FF)
Line Input #FF, b
a = a & b & vbNewLine
Loop
Text1.Text = a
Close
End Sub
text1的OLEDropMode要设为1~
Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim FF As Integer
FF = FreeFile
Dim a As String
Dim b As String
Me.Caption = Data.Files.Item(1)
Open Data.Files.Item(1) For Input As #FF
Do Until EOF(FF)
Line Input #FF, b
a = a & b & vbNewLine
Loop
Text1.Text = a
Close
End Sub
展开全部
如果要显示的内容太多,可以将文本框的multiline属性设置为true,再将文本框的scrollbars属性设定为2。
Private Sub Command1_Click()
Dim str As String
Open "d:\ABC.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str
Text1.Text = Text1.Text & str & vbCrLf
Loop
Close 1
End Sub
Private Sub Command1_Click()
Dim str As String
Open "d:\ABC.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str
Text1.Text = Text1.Text & str & vbCrLf
Loop
Close 1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用下的代码就可以实现
Dim InputData As String, txt As String
Open "完整文件名" For Input As #1
Do While Not EOF(1)
Line Input #1, InputData
txt = txt & vbCrLf & InputData
Loop
Close
Text1.Text = txt
Dim InputData As String, txt As String
Open "完整文件名" For Input As #1
Do While Not EOF(1)
Line Input #1, InputData
txt = txt & vbCrLf & InputData
Loop
Close
Text1.Text = txt
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询