Click here to Skip to main content
15,909,091 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
this is my code

C#
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
        {


            if (Properties.Settings.Default.url == "")
            {

            }
            else
            {
                if (File.Exists(Properties.Settings.Default.url))
                {
                    using (StreamWriter writer = new StreamWriter(Properties.Settings.Default.url, true))
                    {
                        writer.Write(richTextBox1.Text);
                        writer.Close();
                        Properties.Settings.Default.Save();

                    }
                }
                else
                {
                    MessageBox.Show("File Path: " + Properties.Settings.Default.url + " Dose Not Exist");
                }
            }



        }


this just makes sure the file path is there, and it also will write the text to that document, but my problem is that, when it writes the text it really stuffs up the text file for example


instead of the test being "Hello"

and me adding the text " Sup"

it should like this "Hello Sup"

but it would look something like this "HelloHello S HelloSu HelloSup Hello Sup"

it looks very odd i was wondering if anyone can help?
Posted

1 solution

Hi,

Rather than updating the document on richTextBox1_KeyDown, you can achieve the above mentioned details by writing the above code in the richTextBox1_LostFocus event.

But when you will use LostFocus Event, there would a issue when the user comes back and updates the details in Textbox again.

The best possible way round it is save the url Document in a variable and on Lost Focus you could just overwrite the whole document rather than appending.


Regards,
Darshan.
 
Share this answer
 
Comments
[no name] 13-Jul-12 6:59am    
I don't see richTextBox1_LostFocus event. on the event area
darshan_ur 16-Jul-12 5:02am    
Did you try finding the event LostFocus?
[no name] 17-Jul-12 1:33am    
well duh, if, i said i didn't see it, i obliviously didn't find it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900