我正在Visual Basic中编写文字处理器,并且试图使我的应用程序加载从Windows资源管理器打开的文件。我找到了这段代码,但是似乎没有用:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim s As String
s = Command$()
If s <> "" Then
RichTextBox1.LoadFile(s)
Else
'
' Do something else since no file was specified
'
End If
End Sub
有人可以帮忙吗?
答案 0 :(得分:0)
您可以使用OpenFileDialog来模拟Windows资源管理器。
Private Sub FileToRTB()
Dim fName As String = ""
Dim d As New OpenFileDialog
d.Filter = "Rich Text Files (*.rtf)|*.rtf"
If d.ShowDialog = DialogResult.OK Then
fName = d.FileName
RichTextBox1.LoadFile(fName)
End If
End Sub