Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Rich Text Box to Rich Text Box - Help!

Rich Text Box to Rich Text Box - Help!

Scheduled Pinned Locked Moved C#
helpquestiondiscussionannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rvp717y
    wrote on last edited by
    #1

    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.

    L B 3 Replies Last reply
    0
    • R rvp717y

      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.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • R rvp717y

        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.

        B Offline
        B Offline
        bobsugar222
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • R rvp717y

          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.

          B Offline
          B Offline
          bobsugar222
          wrote on last edited by
          #4

          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;

          R 1 Reply Last reply
          0
          • L Luc Pattyn

            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

            R Offline
            R Offline
            rvp717y
            wrote on last edited by
            #5

            Luc, That's kind of what I'm doing now, but I'd like to allow the users to use the full RTF formatting options open to them, including pasting in graphics. Kind regards, John.

            1 Reply Last reply
            0
            • B bobsugar222

              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;

              R Offline
              R Offline
              rvp717y
              wrote on last edited by
              #6

              That's cool - I'll have a play with that over the weekend. I'm glad that it isn't just me and this actually is quite hard! :(( Kind regards, John.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups