This little app works fine, except when the text file opens within the window, I can't type within it or make any changes to the text, other than using the delete key which works normally. Any ideas why this is so? Am I opening it readonly/non-editable somehow?
TIA...
Here is my code:
Code:
Public Class Dialogs
Private strFileName As String
Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
With OpenFileDialog1
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
.Title = "Demo Open File Dialog"
.FileName = ""
.InitialDirectory = "C:\"
End With
'Show the Open dialog and if the user clicks the Open button,
'load the file
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim allText As String
Try
'Save the file name
strFileName = OpenFileDialog1.FileName
'Read the contents of the file
allText = My.Computer.FileSystem.ReadAllText(strFileName)
'Display the file contents in the TextBox
txtFile.Text = allText
Catch fileException As Exception
Throw fileException
End Try
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
With SaveFileDialog1
.DefaultExt = "txt"
.FileName = strFileName
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 1
.OverwritePrompt = True
.Title = "Demo save file dialog"
End With
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
strFileName = SaveFileDialog1.FileName
Dim filePath As String
filePath = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, strFileName)
My.Computer.FileSystem.WriteAllText(filePath, txtFile.Text, False)
Catch fileException As Exception
End Try
End If
End Sub
End Class