|
-
May 2nd, 2008, 06:07 PM
#1
Thread Starter
Addicted Member
[2008] Form3 Close Event
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?
Last edited by kake_fisk; May 2nd, 2008 at 06:15 PM.
-
May 2nd, 2008, 06:20 PM
#2
Re: [2008] Form3 Close Event
 Originally Posted by kake_fisk
...
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:
VB.NET Code:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
-
May 2nd, 2008, 06:43 PM
#3
Thread Starter
Addicted Member
Re: [2008] Form3 Close Event
Okay, thanks, how do i check if the file exist?
-
May 2nd, 2008, 06:51 PM
#4
Re: [2008] Form3 Close Event
Use the System.IO.File.Exists method.
-
May 2nd, 2008, 06:54 PM
#5
Thread Starter
Addicted Member
Re: [2008] Form3 Close Event
Thanks, 
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 = ....
-
May 2nd, 2008, 07:00 PM
#6
Re: [2008] Form3 Close Event
in order to load text rather than save text, you wouldnt use the SaveFile method but the....
-
May 2nd, 2008, 07:06 PM
#7
Thread Starter
Addicted Member
Re: [2008] Form3 Close Event
Yeah, but to be honest, i used this code:
Code:
File.WriteAllText("notes.txt", RichTextBox1.Text)
And don't your :S
-
May 2nd, 2008, 07:10 PM
#8
Re: [2008] Form3 Close Event
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.
-
May 2nd, 2008, 07:13 PM
#9
Thread Starter
Addicted Member
Re: [2008] Form3 Close Event
I tried this code, but it didn't work:
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
Do you have a code that can open notes.txt and then put it into richtextbox1?
Edit: I did also try RichTextBox1.LoadFile("notes.txt")
But got error about the fileformat was invalid...
Last edited by kake_fisk; May 2nd, 2008 at 07:25 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|