Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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

"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
Posted

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

  • *Experts*
Posted

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

"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*
Posted
You could try this:
richTextBox1.LoadFile(filePath & strFileName, RichTextBoxStreamType.RichText);
richTextBox1.SelectionStart = richTextBox1.SelectionLength;
richTextBox1.SelectedText = myStringVar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...