How can i check if the user close form3?
I want the richtextbox to be saved as a .txt file when form3 is closed...
Edit: I found it out: Form3_FormClosing...
But i got another problem, how do i save richtextbox1 to spesial folder mydocuments?
Printable View
How can i check if the user close form3?
I want the richtextbox to be saved as a .txt file when form3 is closed...
Edit: I found it out: Form3_FormClosing...
But i got another problem, how do i save richtextbox1 to spesial folder mydocuments?
You'd use the RichTextBox' SaveFile method. To obtain the path to the My documents folder you'd use:Quote:
Originally Posted by kake_fisk
VB.NET Code:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Okay, thanks, how do i check if the file exist?
Use the System.IO.File.Exists method.
Thanks, :D
But another problem :P
How do i open the file and asign the richtextbox1 with the file's text?
Code:If File.Exists("notes.txt") Then
RichTextBox1.Text = ....
in order to load text rather than save text, you wouldnt use the SaveFile method but the.... ;)
Yeah, but to be honest, i used this code:
And don't your :SCode:File.WriteAllText("notes.txt", RichTextBox1.Text)
yeah well thats fine, you can still use the LoadFile method.
Or any of the file reading methods in the System.IO.File class.
Or the StreamReader.
Theres alot of different choices.
I tried this code, but it didn't work:
Do you have a code that can open notes.txt and then put it into richtextbox1?Code:Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If File.Exists("notes.txt") Then
File.Open("notes.txt", FileMode.Open)
End If
End Sub
Edit: I did also try RichTextBox1.LoadFile("notes.txt")
But got error about the fileformat was invalid...