How do you bind a RichTextBox's Rtf property to a RTF resource at design time?

Go To StackoverFlow.com

0

I have a RichTextBox that I wish to fill with RTF text at design time. This does not mean doing this:

richTextBox1.Rtf = @"<a bunch of rich text>";

which actually assigns the value at run time (or does it?).

I have created a project resource file called "TextResources.resx" with a resource named InstructionsRTF with a Value containing the rich text. How is this to be bound to the RichTextBox at design time?

Edited to add:

@hans-passant is correct, although the exact code I ended up using differs somewhat:

rtfInstructions.Rtf = TextResoures.InstructionsRTF;

where TextResources is the TextResources.resx in the project.

2012-04-04 21:37
by Cyberherbalist


1

RichTextBox doesn't support binding. If it is already a precooked resource then trying to support this at design time doesn't make sense. It is just one line of code in the form constructor:

    public Form1() {
        InitializeComponent();
        richTextBox1.Rtf = Properties.Resources.instructionsRTF;
    }

If you want to get more adventurous at design time then that's possible too. You can create a UITypeEditor that lets you edit the RTF at design time. Code is here.

2012-04-04 21:56
by Hans Passant
Augezeichnet! Thanks very much - Cyberherbalist 2012-04-04 23:24
Why do German users have English user names? Odd. Isn't it "Aus" - Hans Passant 2012-04-04 23:28
I'm American, but I am fairly fluent in German, and since I recognized your name as probably German.. - Cyberherbalist 2012-04-04 23:32
Garlic cross, no, I'm Dutch. We don't like them very much, just their money - Hans Passant 2012-04-04 23:34
Hey! Watch it, my wife's from there! :-) I lived briefly in Brunssum in Limburg long time ago -- wonderful country you have. Found it a bit hard to understand the spoken language, but written Nederlands wasn't too difficult to puzzle out. Bedankt voor uw hulp - Cyberherbalist 2012-04-04 23:46
My first girlfriend was from Limburg. Rimburg, pretty close to Brunssum. Her family moved to the city I lived in after the mines got close down and we met at my school. Language was indeed difficult, they spoke Limburger at dinner. Only 223 kilometers on the map, a world away from the words I knew. I made an effort to learn the dialect but only really got the swear words down pat. Lek mich am asch! Words weren't actually that important at the time, I was 17 and pretty doggone horny all the time : - Hans Passant 2012-04-05 00:08
Ah, such is youth! Wasted on the young. Nice chatting with you - Cyberherbalist 2012-04-05 00:13
Ads