Initializing a RichTextBox

L

Linda Liu [MSFT]

Hi Dave,

I am sorry that I may not understand your question exactly.

Based on my understanding, you'd like to initialize a RichTextBox with a
text stored in a resource file. If I'm off base, please feel free to let me
know.

The Rtf property of RichTextBox gets or sets the text of the RichTextBox
control, including all rich text format (RTF) codes. This property is
typically used when your are assigning RTF text from another RTF source,
such as Microsoft Word or Windows WordPad, to the control.

If you have stored the value of Rtf property of a RichTextBox contol into a
resource file, you could get the value from the resource file and then
assign it to the Rtf property of the RichTextBox control. There should be
no problem.

The following is a sample. It assumes that you have stored the RTF code in
the project's default resource file.

using System.Resources;

private void button1_Click(object sender, EventArgs e)
{
ResourceManager rm = new
ResourceManager(typeof(RichTextBoxProj.Properties.Resources));
this.richTextBox1.Rtf = rm.GetString("MyString");
}

Hope this helps.
If you have anything unclear, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeff Gaines

That's it. I was hoping there was a way to do this without having to call
the
ResourceManager like you can set the Text property in the IDE.

You could always do something like:

this.richTextBox1.Rtf = "something";

I guess it depends how long "something" is?
 
L

Linda Liu [MSFT]

Hi Dave,

Thank you for your reply.

VS IDE doesn't support such a function at present.

I think a possible way is to implement a custom UITypeEditor and then apply
the custom UITypeEditor to the Rtf property. Unfortunately, the Rtf
property is unable to be overridden in a derived RichTextBox class. As for
the custom UITypeEditor, it would be great if there was a 'ResourceEditor'
in .NET class library. Then we could derive the custom UITypeEditor from
the 'ResourceEditor'. Unfortunately again, there's no such a
'ResourceEditor' in .NET class libray.

So it seems that it is not an easy task. In comparison with writing code to
retrieve values from resource files using ResourceManager, the latter is
much easier obviously.

Would you please tell me why you'd like to set the Rtf property with a
value from a resource file at design-time?

Hope this helps.
If you have any concerns, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
G

Guest

Simple solution (I think).

1) Write the text in word and save as an rtf file in the resources
subdirectory.
2) Add each file to the project as an embedded resource.
3) Lead each as follows:
protected void SetHelpPane(string filename)
{
using (Stream stream =
GetType().Assembly.GetManifestResourceStream("WindwardRePortalSystemSetup.Resources." + filename))
{
if (stream != null)
using (StreamReader sr = new StreamReader(stream, Encoding.ASCII))
{
StringBuilder sb = new StringBuilder();
string line;
while ((line = sr.ReadLine()) != null)
sb.Append(line + "\n");
rtfControl.Rtf = sb.ToString();
}
}
}



--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
L

Linda Liu [MSFT]

Hi Dave,

Thank you for sharing your solution to us.

I think it is a good solution to embed and retrieve Rich Text Format text
in project. All of the members in the community will benefit from it.

If you have any questions in the future, please don't hesitate to cotact
us.

Have a nice day!


Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top