Chong Posted October 21, 2003 Posted October 21, 2003 Is there a way to add texts before a RichTextBox file load? Here's my situation. I have a string variable that holds a bunch of data in it. Below is how I load the file into the RichTextBox. richTextBox1.LoadFile(filePath & strFileName, RichTextBoxStreamType.RichText) However, I want to add the string variable to the RichTextBox along with the data that comes from the file load. Another word, I want to combine the two and store into one richtextbox. Is there a way to do this? Any help is greatly appreciated! ljCharlie Quote
*Experts* Nerseus Posted October 21, 2003 *Experts* Posted October 21, 2003 I think you'll have to load the string manually and then shove your original string plus the loaded text in to the RichTextbox yourself. You could also add the string to the front of the textbox after you load the file, but you might notice a visual glitch. Not sure if there's a way to suspend drawing on the RTB while adding text or not. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Chong Posted October 21, 2003 Author Posted October 21, 2003 Thank you very much for the response. I think I like your first idea better. However, how do I load the string plus the text file both into the RTB? The string variable is not store in any database or file....it's created during run time. ljCharlie Quote
*Experts* Nerseus Posted October 21, 2003 *Experts* Posted October 21, 2003 There are lots of ways to read textfiles. I like the following: StreamReader reader = File.OpenText(@"c:\file.txt"); string stringFromFile = reader.ReadToEnd(); Then you can set the RTB's rtf or Text property (I forget) to your two strings, appended together, like: rtb.Text = myString + stringFromFile; -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
*Experts* Volte Posted October 21, 2003 *Experts* Posted October 21, 2003 You could try this:richTextBox1.LoadFile(filePath & strFileName, RichTextBoxStreamType.RichText); richTextBox1.SelectionStart = richTextBox1.SelectionLength; richTextBox1.SelectedText = myStringVar Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.