RTF text in resource file

M

MySelf

Hello,

I am working on a winform app in which I display some text in RTF text
boxes. In particular, I use \n\r chars to skip lines ...

If I directly store theses texts in string objects, the display is
correct and the lines are correctly skipped.

But now I want to store the RTF strings in a RESX resource file. Now I
recover them with

string s = nameOfMyResourceFile.NameOfMyString;

But if I send the recovered string to my RTF textbox, the text is
displayed as simple text, and \n\r chars are displayed in spite of
being interpreted to skip lines.

So how can I store the RTF string in a RESX file, and recover them as
RTF text that can be correctly display in RTF textboxes ?$

Thank you for any help.
 
M

MySelf

Peter Duniho a écrit :
"\r\n" is the usual Windows line terminator. And they don't really have much
to do with RTF specifically.

Thank you for your answer.

So if \n\r are not RTF specific, let say it's just the \n\r chars
which are no more interpreted as a newline constant.

If I store the strings in the .cs file as constantes like this :

private const string SAY_HELLO = "Hello \n\r People !";

and if I use them the following way :

myRichTextTextBox.Text = SAY_HELLO;

the text "Hello People" appear on the textbox on 2 lines.

But if I store the same string ("Hello \n\r People !") in a RESX file
named MyResxFile.resx , name it SAY_HELLO_STRING and use it the
following way :

myRichTextTextBox.Text = MyResxFile.SAY_HELLO_STRING;

I get the string appearing on the TextBox on one line, with characters
\n\r displayed between the two words "HELLO" and "PEOPLE". These two
characters are no more interpreted as a newline constant ...
 
J

Jeff Johnson

So if \n\r are not RTF specific, let say it's just the \n\r chars which
are no more interpreted as a newline constant.

Please note that you have these BACKWARDS. I'm not saying it's going to fix
your problem or anything (they aren't RTF escape code), but \n\r is LFCR,
when Windows/DOS uses CRLF. In other words, a true line separator is \r\n,
NOT \n\r. Again, this is outside the realm of RTF; I mention it only for
correctness.
 
M

MySelf

rossum a émis l'idée suivante :
Standard RTF for a linefeed is \line Does that work better?

rossum

Tried \line, but with the same result. It is just displayed in the
textbox.
 
M

MySelf

Peter Duniho avait écrit le 24/02/2011 :
You don't explain how you are setting the string in your "MyResxFile.resx",
but the bottom line is that you need _actual_ newline characters in your
resource, not the characters that the C# compiler would treat as special
escaped characters.

Well, I just created a new Resource file (Add Item ==> New Item ==>
Resources file) , then double clicked on the file, opened it and typed
the strings directly into the file.
 
M

MySelf

Après mûre réflexion, Peter Duniho a écrit :
Yes. It's amazing what a simple web search can turn up. If one actually
tries. :)

I tried it before I post. It's just that I got lost into RTF subjects,
before you told me it was not a RTF problem.
 
J

Jeff Johnson

Tried \line, but with the same result. It is just displayed in the
textbox.

That's because you're probably (and I say probably, because even though
we've asked you to show your code, you haven't) using the Text property and
not the Rtf property. RTF codes will only be interpreted when you set the
Rtf (or SelectedRtf) property.
 
M

MySelf

Dans son message précédent, Jeff Johnson a écrit :
That's because you're probably (and I say probably, because even though we've
asked you to show your code, you haven't) using the Text property and not the
Rtf property. RTF codes will only be interpreted when you set the Rtf (or
SelectedRtf) property.

My problem is solved, because my concern was about \r\n, which appeared
to be not RTF characters.

But I find your remark very interesting, in case I really need to
manage RTF text.
Thank you.
 
M

MySelf

Il se trouve que MySelf a formulé :
Après mûre réflexion, Peter Duniho a écrit :

I tried it before I post. It's just that I got lost into RTF subjects, before
you told me it was not a RTF problem.

I hope it will not turn to be a RTFM problem ... ;-)
 

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