load text 2 richtxtbox
Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts
Page 1 of 1
It seems easy but i can't fiqure it out
loading a reguler .txt file into a richtextbox1 with an opendialogbox
also saving it...
loading a reguler .txt file into a richtextbox1 with an opendialogbox
also saving it...
Open File:
Code: Select all
Save As:
Try
Dim cf As String
OpenFileDialog1.Title = "RTE - Open File"
OpenFileDialog1.DefaultExt = "rtf"
OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt|Rich Text Files (*.rtf)|*.rtf|HTML Files (*.htm,*.html)|*.htm,*.html|VB Files (*.vb)|*.vb|PHP Files (*.php)|*.php|All Files (*.*)|*.*"
OpenFileDialog1.FilterIndex = 1
OpenFileDialog1.ShowDialog()
Label1.Text = OpenFileDialog1.SafeFileName
Label2.Text = OpenFileDialog1.FileName
If OpenFileDialog1.FileName = "" Then Exit Sub
Dim strExt As String
strExt = System.IO.Path.GetExtension(OpenFileDialog1.FileName)
strExt = strExt.ToUpper()
Select Case strExt
Case ".RTF"
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
Case Else
Dim txtReader As System.IO.StreamReader
txtReader = New System.IO.StreamReader(OpenFileDialog1.FileName)
RichTextBox1.Text = txtReader.ReadToEnd
txtReader.Close()
txtReader = Nothing
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = 0
End Select
cf = OpenFileDialog1.FileName
RichTextBox1.Modified = False
Catch EX As Exception
MsgBox("Unidentified Error!!", MsgBoxStyle.Critical)
End Try
Code: Select all
Save File:
SaveFileDialog1.Title = "RTE - Save File"
SaveFileDialog1.DefaultExt = "rtf"
SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt|Rich Text Files (*.rtf)|*.rtf|HTML Files (*.htm,*.html)|*.htm,*.html|All Files (*.*)|*.*"
SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName = "" Then Exit Sub
Dim strExt As String
strExt = System.IO.Path.GetExtension(SaveFileDialog1.FileName)
strExt = strExt.ToUpper()
Select Case strExt
Case ".RTF"
RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.RichText)
Case ".TXT"
Dim confirm As Integer
confirm = MsgBox("All formatting will be lost if you save it in the .txt format. You should save the file in the .rtf format to save the file with the formatting. Would you like to continue saving the file in the .txt format?", vbYesNo + vbQuestion)
If confirm = vbYes Then
Dim txtWriter As System.IO.StreamWriter
txtWriter = New System.IO.StreamWriter(SaveFileDialog1.FileName)
txtWriter.Write(RichTextBox1.Text)
txtWriter.Close()
txtWriter = Nothing
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = 0
Else
SaveFileDialog1.ShowDialog()
End If
Case Else
Dim txtWriter As System.IO.StreamWriter
txtWriter = New System.IO.StreamWriter(SaveFileDialog1.FileName)
txtWriter.Write(RichTextBox1.Text)
txtWriter.Close()
txtWriter = Nothing
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = 0
End Select
cf = SaveFileDialog1.FileName
RichTextBox1.Modified = False
Code: Select all
Please +rep if this helps cooll;Dim cf As String
If cf = "" Then
SaveAsToolStripMenuItem.PerformClick()
Exit Sub
End If
Dim strExt As String
strExt = System.IO.Path.GetExtension(cf)
strExt = strExt.ToUpper()
Select Case strExt
Case ".RTF"
RichTextBox1.SaveFile(cf)
Case Else
Dim txtWriter As System.IO.StreamWriter
txtWriter = New System.IO.StreamWriter(cf)
txtWriter.Write(RichTextBox1.Text)
txtWriter.Close()
txtWriter = Nothing
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = 0
RichTextBox1.Modified = False
End Select
Instead of LOL use this -
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
lesan101 wrote:awesome +Rep'dActually this was the code I used in my Notepad app.
So I just copy+pasted the from my app!
Anyways thanks for the +rep!
Instead of LOL use this -
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
4 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023