none
Saving richtextbox contents as RTF results in different spacing RRS feed

  • Question

  • I'm writing a chordpro interpreter; this takes plain text song information and converts into a formatted page. I produce the formatted text in a richtextbox. It looks fine in the RTB and if I save the contents using a third party RTB to PDF, it's fine, but if I use the richtextbox.savefile() method, the resulting RTF looks different - critically, the chords are in the wrong places. If I save the contents of a richtextbox and then load that saved file into Word, I'd expect it to look the same, but it doesn't. Any suggestions? I've attached an image showing the problem. I position the chords by inserting non-breaking spaces in front the characters and using TextRenderer.MeasureText() to measure the resulting whitespace until the chord's in the right place.



    AndrewFromEssex

    Saturday, February 10, 2018 1:32 PM

All replies

  • Hi

    I have also had sleepless nights over this kind of thing. It would seem that there is no 'easy' way to position text in a way that is 'transferable'.

    What I ended up doing, was to use a mono width font which sort of guarantees alignment at the expense of limiting fonts available.

    Another thing I experimented with to a fair degree of success (only in the display of the data) was to use formatting such as:

    For Each result In queryResults
          RichTextBox1.AppendText(result.cust.CompanyName
              .PadRight(20) & "(ID " & result.ord.CustomerID &
              ")".PadRight(4) & result.ord.d
              .ToString("ddd, dd MMM yyyy").PadRight(12) &           result.ord.Amount.ToString("C", CultureInfo.CurrentCulture)
              .PadLeft(16) & vbCrLf)
        Next
    I don't think that this type of formatting would transfer into Word etc in any better a way than you are finding at the moment, but,may be worth a try.


    Regards Les, Livingston, Scotland

    Saturday, February 10, 2018 2:02 PM
  • Hi Les, thanks for the quick reply; glad it's not just me. What I might try is using a monospaced font for the positioning, pdf does work, so I sort of have a workaround.


    AndrewFromEssex

    Saturday, February 10, 2018 2:10 PM
  • Hi Les, thanks for the quick reply; glad it's not just me. What I might try is using a monospaced font for the positioning, pdf does work, so I sort of have a workaround.


    AndrewFromEssex

    Yes try mono type font as you say.

    You could use tabs I think? See Razerz last example here:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/4fea01ea-3328-4073-8105-8b0b69e824c1/creating-or-finding-a-ruler-control-that-supports-marking-margins-indents-and-tabs?forum=vbgeneral

    Saturday, February 10, 2018 3:13 PM