RichTextBox

  • Thread starter Thread starter Tank
  • Start date Start date
T

Tank

I have RichTextBox in my dialog. Currently, I am loading the content from a
file. Is there anyway to have the text 'binded' to it during compile time ?
The idea is not to distribute the rtf file when installing the application.
 
Er.. how ? The problem is the text consists of a mix of bolded and
non-bolded text. Also some words use different font.
 
true but the underlying RTF is just tagged text....

{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17 Here is the text\par
}
 
You can include the RTF file as an embedded resource and load it from
the assembly.

Add the file:
Project -> Add Existing Item

Right click on it in Solution Explorer and select:
Build Action -> Embedded Resource

Then use code like this to load it:

using System.Reflection;

Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream =
assembly.GetManifestResourceStream("RTFtest.testFile.rtf"))
{
richTextBox.LoadFile(stream, RichTextBoxStreamType.RichText);
}

where 'RTFtest' is the default namespace for the project.

- Magnus
 
I have a rtf file "abc.rtf", namespace is MyNamespace.

assembly.GetManifestResourceStream("MyNamespace.abc.rtf")) gave me an error.

Is that the correct way to specify the resource name ?
 
Thanks. I got it. Please ignore my last post.

Magnus Krisell said:
You can include the RTF file as an embedded resource and load it from
the assembly.

Add the file:
Project -> Add Existing Item

Right click on it in Solution Explorer and select:
Build Action -> Embedded Resource

Then use code like this to load it:

using System.Reflection;

Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream =
assembly.GetManifestResourceStream("RTFtest.testFile.rtf"))
{
richTextBox.LoadFile(stream, RichTextBoxStreamType.RichText);
}

where 'RTFtest' is the default namespace for the project.

- Magnus

from time
 
Thanks. It works fine that way.

Another question is :

How do I get the default namespace of the project programatically ? The idea
is not to hardcode the parameter "RTFtest.testFile.rtf" so that I can do
something like this :

assembly.GetManifestResourceStream(GetDefaultProjNameSpace()+".testFile.rtf"
));

Thanks in advance.
 
Back
Top