Loading embedded resource .rtf file in richtextbox when loading C #

Ok, so I read about loading inline rtf into an advanced text field, and I'm trying to do this when the form loads. The form is not the main form, it is the second form that loads when the control is clicked. This is what I have in the form on boot:

private void Credits_Load(object sender, EventArgs e) { Assembly creditAssm = Assembly.GetExecutingAssembly(); using (Stream creditStream = creditAssm.GetManifestResourceStream("YDisplayView.credits.rtf")) { creditsRichTextBox.LoadFile(creditStream, RichTextBoxStreamType.RichText); } } 

In the solution explorer, the rtf file is displayed as a resource, and an embedded resource is installed for the assembly action.

when I click the button to load the form, it displays as expected, but nothing happens. Rtf content doesn't seem to show: /

I can only assume that I am doing it wrong :(

Any help for this newbie would be appreciated.

+4
source share
2 answers

I understood:

 creditAssm.GetManifestResourceStream("YDisplayView.credits.rtf")) 

should be:

 creditAssm.GetManifestResourceStream("YDisplayView.Resources.credits.rtf")) 

Edit: For some reason this time, I cannot get the above code to work, but I found another one that I hope will / will be useful for new coders :)

 string rtf = yourAppName.Properties.Resources.yourEmbeddedRTFName; yourRichTextBox.Rtf = rtf; 
+9
source

I wanted to create an rtf help file named Help.rtf and save it as a resource so that it could be downloaded when the help form was downloaded without freezing the Help.rtf help folder.

I found that I need to add the rtf file to resources through the menu Project-> 'Your namespace' Properties ... , then go to the Resources tab, then Add item, etc. etc. before intellisense would suggest the rtf file in the dropdown when I typed "My.Resource". Now a list of resources is displayed, including the help file that I added (without the extension, which is normal).

In short, once this was done, then it worked:

 RichTextBox1.rtf = My.Resources.Help 

Apparently, just dragging, dropping, copying, or even adding a file using Solution Explorer is not enough!

It's been 3 days on this issue, so I hope someone finds this helpful.

+2
source

Source: https://habr.com/ru/post/1340280/


All Articles