WPF RichTextBox Tab question

A van Lienden 1 Reputation point
2021-03-01T09:36:16.02+00:00

The WPF RichTextBox does not support adjusting the tab size. I would expect that a tabwidth of 720 twips would be used, since that's the default of the rtf specification. However, I do find a difference when showing the rtf document below. On the one hand there's the RichTextBox that shows the words 'Hospital' directly beneath one another. On the other hand there's Microsoft Word (tested with v2019) and DevExpress' RichEditControl that show the word 'Hospital' on the second line more to the left. I'm looking for a way to show the document in the same way in all controls. Is there public information available on how the RichTextBox processes the rtf document? Can I maybe adjust some settings to fix this issue? Maybe the used tabwidth is documented somewhere? I couldn't find it so far.

{\rtf1
{\fonttbl{\f0\fcharset0 Segoe UI;}}
{{ First line text text te,\tab Hospital}\par}
{{ Londi\tab \tab \tab Hospital}\par}
}
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,694 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 113.7K Reputation points
    2021-03-01T12:27:28.88+00:00

    Consider an alternative: borderless tables. Try an example:

    {\rtf1
    {\fonttbl{\f0\fcharset0 Segoe UI;}}
    
    \trowd \cellx2000 \cellx3000
    First line\intbl\cell Hospital\intbl\cell \row
    
    \trowd \cellx2000 \cellx3000
    Second line\intbl\cell Hospital\intbl\cell \row
    
    }
    

    Using \cellx you can set the width of the columns.

    You can export some experimental tables from Word and maybe check the RTF Specification.


  2. DaisyTian-1203 11,616 Reputation points
    2021-03-08T02:39:08.067+00:00

    How about add fs** to the each par, I updated your rtf content as below:

    {\rtf1  
     {\fonttbl{\f0\fcharset0 Segoe UI;}}  
     {  
                     {\fs20 First line text text te,\tab Hospital}\par}  
     {  
                     {\fs20 Londi\tab \tab \tab Hospital}\par}  
     }  
    

    The the \tab can work , and words Hospital directly beneath one another.
    75202-capture.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments