I am trying to load the content of an RTF file, which I have put inside resources (through Project->Properties->Resources->Add File
).
I want to load Agreement.rtf
's content to a RichTextBox
and I have tried the following:
Dim stream As Stream
stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(My.Resources.ResourceManager.GetObject("Agreement").GetType(), "IOpzioni.Agreement.rtf")
RichTextBox1.SelectAll()
RichTextBox1.Selection.Load(stream, DataFormats.Rtf)
also
stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(My.Resources.Agreement.GetType(), "IOpzioni.Agreement.rtf")
IOpzioni
is my default namespace (I have double checked that).
Nothing seems to work. What is the correct way to do this?
I achieved this in a somewhat simple way in my WPF application. See my blog here: http://devdare.blogspot.com/2014/03/wpf-loading-rtf-document-in-richtextbox.html
Resources.resx
file (if it's not already
there)RTFDoc.rtf
in your Resources.resx fileResources.resx
file, there would be code behind file: Resources.Designer.cs
. Open it and copy its namespace and class name. In my case it is Surf.Resources.Resource1
I used this to load the RTF resource in my WPF RichTextBox
control. Here are the lines from the code behind:
using Surf.Resources;
void Surface_Loaded(object sender, RoutedEventArgs e)
{
var stream = new MemoryStream(Encoding.Unicode.GetBytes(Resource1.RTFDoc));
RichTextBox1.Selection.Load(stream, DataFormats.Rtf);
}
Surf is my project name here. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With