4

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?

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Paweł Poręba
  • 1,084
  • 1
  • 14
  • 37

3 Answers3

5

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.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • When I store a `.rtf` file as resource, it is added to `Files` category. It's true that later using `Properties.Resources.MyRTFResourceName` returns `string` with `RTF` formatting, but there's no possibility for me to change it's `Persistence` property to `Embdeeded with .resx`. Can I do anything about it? – Paweł Poręba Jan 21 '16 at 13:44
  • Thanks I used this and it helped me out – Jonathan Shields Mar 14 '18 at 11:54
0

i don't sure it's will work for C#, i code this for .Net try to convert this code.

RichTextBox1.LoadFile(Application.StartupPath & "\user_guide.rtf")

well that's my code on "VB.NET"

0

This is just the folder where your files are laying on your disk. Somewhere in your project, there is also a .resx file (probably under Properties). Open that file by a double-click and drag-drop your .rtf file from the solution explorer over the designer view of the .resxfile.

Oliver
  • 43,366
  • 8
  • 94
  • 151
  • Hi. That almost solves my problem. I mean, I can refference the files from `Resources`, but I can't change `Persistence` property for them to be `Embdeeded with .resx` as I might to with Images. Have you any idea why it is like that? – Paweł Poręba Jan 21 '16 at 13:41