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. Other Discussions
  3. Clever Code
  4. Not all roads lead to rome...

Not all roads lead to rome...

Scheduled Pinned Locked Moved Clever Code
csharphelpquestiondiscussion
7 Posts 4 Posters 6 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.
  • M Offline
    M Offline
    mav northwind
    wrote on last edited by
    #1

    Recently I stumbled across a nice little bug in .NET while working with RichTextBoxes... Consider the following code snipplet:

    RichTextBox _rtb = new RichTextBox();
    // ...
    // fill the RTB
    // ...

    // get all the formatted Text in RTF format:
    string rtf1 = _rtb.Rtf;

    // alternative way:
    _rtb.Select(0, _rtb.Text.Length); // select everything
    string rtf2 = _rtb.SelectedRtf; // get the selection

    What do you think - is it reasonable to assume that rtf1 contains the same RTF as rtf2? Solution coming up later...

    Regards, mav -- Black holes are the places where God divided by 0...

    L R 2 Replies Last reply
    0
    • M mav northwind

      Recently I stumbled across a nice little bug in .NET while working with RichTextBoxes... Consider the following code snipplet:

      RichTextBox _rtb = new RichTextBox();
      // ...
      // fill the RTB
      // ...

      // get all the formatted Text in RTF format:
      string rtf1 = _rtb.Rtf;

      // alternative way:
      _rtb.Select(0, _rtb.Text.Length); // select everything
      string rtf2 = _rtb.SelectedRtf; // get the selection

      What do you think - is it reasonable to assume that rtf1 contains the same RTF as rtf2? Solution coming up later...

      Regards, mav -- Black holes are the places where God divided by 0...

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      mav.northwind wrote:

      What do you think - is it reasonable to assume that rtf1 contains the same RTF as rtf2?

      No, rtf1 will included document info too. rtf2 might attach info differently (as needed). [update] what I said is actually well documented [update]

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      M 1 Reply Last reply
      0
      • L leppie

        mav.northwind wrote:

        What do you think - is it reasonable to assume that rtf1 contains the same RTF as rtf2?

        No, rtf1 will included document info too. rtf2 might attach info differently (as needed). [update] what I said is actually well documented [update]

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4a out now (29 May 2008)

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        While this may be true, it's not what I meant (btw. where did you find this information?). Even if there's no additional document info, there's a visible difference. _rtb.Rtf contains an additional newline (\par) at the end and switches the font back to the RTB's default font. So if you have 2 RTB's and want to insert the first one's contents at a given position into the second one, you won't get the correct results, unless you don't use _rtb.Rtf but _rtb.SelectedRtf.

        Regards, mav -- Black holes are the places where God divided by 0...

        L 1 Reply Last reply
        0
        • M mav northwind

          While this may be true, it's not what I meant (btw. where did you find this information?). Even if there's no additional document info, there's a visible difference. _rtb.Rtf contains an additional newline (\par) at the end and switches the font back to the RTB's default font. So if you have 2 RTB's and want to insert the first one's contents at a given position into the second one, you won't get the correct results, unless you don't use _rtb.Rtf but _rtb.SelectedRtf.

          Regards, mav -- Black holes are the places where God divided by 0...

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          mav.northwind wrote:

          btw. where did you find this information?

          MSDN docs! :) Rtf is used for 'loading' a complete document. SelectedRtf is for 'inserting/selecting' a chunk of RTF.

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          M 1 Reply Last reply
          0
          • L leppie

            mav.northwind wrote:

            btw. where did you find this information?

            MSDN docs! :) Rtf is used for 'loading' a complete document. SelectedRtf is for 'inserting/selecting' a chunk of RTF.

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            M Offline
            M Offline
            mav northwind
            wrote on last edited by
            #5

            leppie wrote:

            MSDN docs! [Smile]

            :) oh come on! I was hoping for a link about document information in RTF documents... Nevertheless, Rtf will give you a newline that simply isn't there.

            Regards, mav -- Black holes are the places where God divided by 0...

            S 1 Reply Last reply
            0
            • M mav northwind

              Recently I stumbled across a nice little bug in .NET while working with RichTextBoxes... Consider the following code snipplet:

              RichTextBox _rtb = new RichTextBox();
              // ...
              // fill the RTB
              // ...

              // get all the formatted Text in RTF format:
              string rtf1 = _rtb.Rtf;

              // alternative way:
              _rtb.Select(0, _rtb.Text.Length); // select everything
              string rtf2 = _rtb.SelectedRtf; // get the selection

              What do you think - is it reasonable to assume that rtf1 contains the same RTF as rtf2? Solution coming up later...

              Regards, mav -- Black holes are the places where God divided by 0...

              R Offline
              R Offline
              Ri Qen Sin
              wrote on last edited by
              #6

              Working with a huge blob of RTF text is a nightmare… I'd much prefer using WPF's RichTextBox control. It provides a structured representation of all the elements in the document (much like HTML or XML). You might want to consider embedding one in your Windows Forms project.

              So the creationist says: Everything must have a designer. God designed everything. I say: Why is God the only exception? Why not make the "designs" (like man) exceptions and make God a creation of man?

              1 Reply Last reply
              0
              • M mav northwind

                leppie wrote:

                MSDN docs! [Smile]

                :) oh come on! I was hoping for a link about document information in RTF documents... Nevertheless, Rtf will give you a newline that simply isn't there.

                Regards, mav -- Black holes are the places where God divided by 0...

                S Offline
                S Offline
                Simon Capewell
                wrote on last edited by
                #7

                mav.northwind wrote:

                I was hoping for a link about document information in RTF documents...

                That wouldn't be much use, they change them daily in an attempt to make Google look bad!

                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