Dipojjal
Dipojjal

Reputation: 71

How to preserve text formatting in RichTextBox like Bold, Italics, font color, font size, etc?

I have created an application and for that application, I have designed a help file in Microsoft word. The help file is too long. So I decided to use the RichTextBox control in vb.net. I copied all the content from the word file. Now, I need to preserve the text formatting I have done in the actual file (like bold, italics, etc).

How can I preserve the text formatting?

Is there any other way I can display the help file in vb.net with properly formatted text?

Upvotes: 2

Views: 2194

Answers (2)

Chris
Chris

Reputation: 8647

RichTextBox supports rtf content, you can't directly paste the Word content in your RichTextBox .

You need to convert the word document into .rtf file. Best way is to use the save As dialog in Microsoft Word.

Then you could deploy the document with your application and then load rtf content in your RichTextBox using LoadFile method.

RichTextBox1.LoadFile("Help-File.rtf")

Obviously, it supposes that basic formatting like mentioned in title (Bold, Italics, font color, font size, ...) are enough for this purpose, since the rft format does not support all MS Word features.

Otherwise you may have to implement your own parse/interpretation logic.

Upvotes: 2

Dipojjal
Dipojjal

Reputation: 71

Here is how I did it:

I converted the word document int rtf format using the save as dialog box in microsoft word. Then copied the file named "help-file.rtf" into the executable folder (the executable is generally present within the debug or Release folder).

Copy the file in rtf format to the application executable folder and then use the following function:

RichTextBox1.LoadFile("Help-File.rtf")

Here, RichTextBox1 is the name of the RichTextBox control. Use the function above to load the file into the RichTextBox control.

Upvotes: 0

Related Questions