【问题标题】:How can I open a file from Windows Explorer and load it into a rich text control?如何从 Windows 资源管理器打开文件并将其加载到富文本控件中?
【发布时间】:2020-04-14 21:30:25
【问题描述】:

我正在用 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

谁能帮忙?

【问题讨论】:

标签: vb.net richtextbox file-format


【解决方案1】:

您可以使用 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-30
    • 2012-05-05
    • 2014-12-12
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 2010-09-24
    相关资源
    最近更新 更多