Rich Text Box to Rich Text Box - Help!
-
Hi there, I'm creating an application to securely record information typed in by the user. A main window (let's call it 'A') with a large RTF box displays the text so far - this text box is read-only to preserve the integrity of previous entries, so no editing is allowed here. When the user wants to post a new entry the they click a button and a new RTF box appears (call this one 'B') - into this the user can type or paste RTF compliant entries, when done, clicks "OK" and the contents of this RTF box (B) need to be added to the read-only main window (A). I don't have a problem with the protection and getting stuff from B into A - however I have a major problem maintaining the RTF formatting when taking the contents of one RTF control and appending it to the contents of the other read-only version! I don't want to save RTF from B to file and read that in to A as this will present the opportunity to subvert the process and add additional material. Likewise, I can make this work very reliably if I stick with plain text - but the moment I want to retain the RTF formatting it all gets very hard. Any thoughts? Kind regards, John.
-
Hi there, I'm creating an application to securely record information typed in by the user. A main window (let's call it 'A') with a large RTF box displays the text so far - this text box is read-only to preserve the integrity of previous entries, so no editing is allowed here. When the user wants to post a new entry the they click a button and a new RTF box appears (call this one 'B') - into this the user can type or paste RTF compliant entries, when done, clicks "OK" and the contents of this RTF box (B) need to be added to the read-only main window (A). I don't have a problem with the protection and getting stuff from B into A - however I have a major problem maintaining the RTF formatting when taking the contents of one RTF control and appending it to the contents of the other read-only version! I don't want to save RTF from B to file and read that in to A as this will present the opportunity to subvert the process and add additional material. Likewise, I can make this work very reliably if I stick with plain text - but the moment I want to retain the RTF formatting it all gets very hard. Any thoughts? Kind regards, John.
I suggest when you add some RTF text, you also add whatever commands are required to return all text attributes to their neutral settings (i.e. default font, not bold, not italic, black, etc) plus a new line; as a result each consecutive piece of RTF will start from the same known situation. :)
Luc Pattyn
-
Hi there, I'm creating an application to securely record information typed in by the user. A main window (let's call it 'A') with a large RTF box displays the text so far - this text box is read-only to preserve the integrity of previous entries, so no editing is allowed here. When the user wants to post a new entry the they click a button and a new RTF box appears (call this one 'B') - into this the user can type or paste RTF compliant entries, when done, clicks "OK" and the contents of this RTF box (B) need to be added to the read-only main window (A). I don't have a problem with the protection and getting stuff from B into A - however I have a major problem maintaining the RTF formatting when taking the contents of one RTF control and appending it to the contents of the other read-only version! I don't want to save RTF from B to file and read that in to A as this will present the opportunity to subvert the process and add additional material. Likewise, I can make this work very reliably if I stick with plain text - but the moment I want to retain the RTF formatting it all gets very hard. Any thoughts? Kind regards, John.
I assume you have been trying to do something like:
rtfReadOnly.Rtf += rtfEdit.Rtf;
The problem is that you will be binding two complete rtf documents together. Which will end up with invalid rtf. You should read up on the rtf format as I think you will have you modify the raw rtf strings of both rtfs before binding them together. By this I mean removing the rtf header from the rtf doc you are trying to add and the trailing '}' from the readonly rtf.
-
Hi there, I'm creating an application to securely record information typed in by the user. A main window (let's call it 'A') with a large RTF box displays the text so far - this text box is read-only to preserve the integrity of previous entries, so no editing is allowed here. When the user wants to post a new entry the they click a button and a new RTF box appears (call this one 'B') - into this the user can type or paste RTF compliant entries, when done, clicks "OK" and the contents of this RTF box (B) need to be added to the read-only main window (A). I don't have a problem with the protection and getting stuff from B into A - however I have a major problem maintaining the RTF formatting when taking the contents of one RTF control and appending it to the contents of the other read-only version! I don't want to save RTF from B to file and read that in to A as this will present the opportunity to subvert the process and add additional material. Likewise, I can make this work very reliably if I stick with plain text - but the moment I want to retain the RTF formatting it all gets very hard. Any thoughts? Kind regards, John.
I managed to get it to work. Try this:
string rtf1 = rtfReadOnly.Rtf.TrimEnd("}\r\n".ToCharArray());
string rtf2 = rtfEdit.Rtf.TrimStart(@"{\\rtf1".ToCharArray());
rtfReadOnly.Rtf = rtf1 + rtf2; -
I suggest when you add some RTF text, you also add whatever commands are required to return all text attributes to their neutral settings (i.e. default font, not bold, not italic, black, etc) plus a new line; as a result each consecutive piece of RTF will start from the same known situation. :)
Luc Pattyn
-
I managed to get it to work. Try this:
string rtf1 = rtfReadOnly.Rtf.TrimEnd("}\r\n".ToCharArray());
string rtf2 = rtfEdit.Rtf.TrimStart(@"{\\rtf1".ToCharArray());
rtfReadOnly.Rtf = rtf1 + rtf2;