I am trying to read a txt file into a richtextbox and been doing some research and from what I read this should work, but I get a error saying that the file format is not valid. I thought that the richtextbox control can read txt files as well as rtf files automatically. The file I am trying to read is saved in Notepad as a txt file. I can open the file if it is rtf, but not if it is a txt. Any Ideas why it wouldn't work? I am also attaching the textfile I am trying to use. Here is what I got so far.
CODE
Option Strict On
Option Explicit On
Public Class frmMain
Private Sub OpenFile()
Dim Result As DialogResult
Result = ofdMain.ShowDialog
If Result = Windows.Forms.DialogResult.OK Then
rtbNotes.LoadFile(ofdMain.FileName, RichTextBoxStreamType.RichText)
End If
tsslFileName.Text = ofdMain.FileName
End Sub
Private Sub SaveFile()
Dim Result As DialogResult
Result = sfdMain.ShowDialog
If Result = Windows.Forms.DialogResult.OK Then
rtbNotes.SaveFile(sfdMain.FileName, RichTextBoxStreamType.RichText)
End If
End Sub
Private Sub NavigateFirst()
rtbNotes.SelectionStart = 0
rtbNotes.SelectionLength = 0
End Sub
Private Sub NavigateLast()
rtbNotes.SelectionStart = rtbNotes.Text.Length - 1
End Sub
Private Sub msExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msExit.Click
Me.Close()
End Sub
Private Sub msOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msOpen.Click
Call OpenFile()
End Sub
Private Sub msSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msSave.Click
Call SaveFile()
End Sub
Private Sub tsOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsOpen.Click
Call OpenFile()
End Sub
Private Sub tsSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsSave.Click
Call SaveFile()
End Sub
End Class
This post has been edited by snssewell: 15 Jan, 2008 - 10:49 AM