Search code examples
vb.netrichtextboxopenfiledialog

How to view a text file in a richtextbox without a openfiledialog in VB.NET


I want to open a text file into a richtextbox without using a OpenFileDialog in VB.NET


Solution

  • In VB.NET 2012. Something like this works

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            Me.RichTextBox1.LoadFile("C:\MyDocument.rtf", RichTextBoxStreamType.PlainText)
        End Sub
    End Class
    

    Take a look at the RichTextBoxStreamType Enumeration

    http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.richtextboxstreamtype(v=vs.90).aspx