Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading .rtf file from resources into RichTextBox

I've seen some topics on this subject but none of them wants to work in my case. In my Windows Forms app I have a ordinary Resourcescatalog containing some images and .rtf files. It looks like this:

enter image description here

There's no problem for me to load pictures from it as:

Bitmap bmp = Properties.Resources.Cut_6523;

But, for some reason, I am unable to do the same with .rtf files (only bitmaps are available).

What am I doing wrong?

like image 768
Paweł Poręba Avatar asked Sep 14 '25 19:09

Paweł Poręba


1 Answers

When you store a .rft file as resource using resource designer, the resource designer creates a string property for it that returns rich text.

So you can set the content of RichTextBox to rich text using SelectedRtf property.

this.richTextBox1.SelectAll();
this.richTextBox1.SelectedRtf = Properties.Resources.YourRTFResourceName;

Also as another option, you can cache that resource as a file in your application directory at run-time and then use richTextBox1.LoadFile to load rich text.

like image 75
Reza Aghaei Avatar answered Sep 16 '25 09:09

Reza Aghaei