Loading embedded resource .rtf file into richtextbox on load C#

BrandNewDev picture BrandNewDev · Feb 18, 2011 · Viewed 11.6k times · Source

Ok so I read about loading an embedded rtf into a rich text box and I am trying to do it when the form loads. The form is not the main form, it is a second form that loads when a control is clicked. This is what I have on the form when it loads:

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 shows as a resource and the build action is set to embedded resource.

when I click the button to load the form, it shows as expected, but nothing happens. The contents of the rtf doesn't seem to show :/

I can only assume I am doing it wrong :(

Any help for this newbie would be appreciated.

Answer

BrandNewDev picture BrandNewDev · Feb 19, 2011

I figured it out:

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

needed to be:

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

Edit: For some reason this time around I can't get the above code to work but I found another one that did so hopefully either/or will be of some help to new coders out there :)

string rtf = yourAppName.Properties.Resources.yourEmbeddedRTFName;
        yourRichTextBox.Rtf = rtf;