Search code examples
c#winformsrichtextboxembedded-resourcertf

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?


Solution

  • 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.