Results 1 to 9 of 9

Thread: [2008] Form3 Close Event

  1. #1

    Thread Starter
    Addicted Member kake_fisk's Avatar
    Join Date
    May 2008
    Posts
    207

    [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.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Form3 Close Event

    Quote 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:
    1. Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Addicted Member kake_fisk's Avatar
    Join Date
    May 2008
    Posts
    207

    Re: [2008] Form3 Close Event

    Okay, thanks, how do i check if the file exist?

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Form3 Close Event

    Use the System.IO.File.Exists method.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Addicted Member kake_fisk's Avatar
    Join Date
    May 2008
    Posts
    207

    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 = ....

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008] Form3 Close Event

    in order to load text rather than save text, you wouldnt use the SaveFile method but the....
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  7. #7

    Thread Starter
    Addicted Member kake_fisk's Avatar
    Join Date
    May 2008
    Posts
    207

    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

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  9. #9

    Thread Starter
    Addicted Member kake_fisk's Avatar
    Join Date
    May 2008
    Posts
    207

    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
  •  



Click Here to Expand Forum to Full Width