question

AvanLienden-1483 avatar image
0 Votes"
AvanLienden-1483 asked ·

WPF RichTextBox Tab question

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-wpf
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered ·

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.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for the alternative! I hoped it would be possible to adjust the document in code to make the document have the same layout in the mentioned editors. Lots of documents have already been created.

You don't know if the tab-processing of the RichTextBox is somewhere available (in code or documentation)? I couldn't find it yet.

0 Votes 0 ·
DaisyTian-MSFT avatar image
0 Votes"
DaisyTian-MSFT answered ·

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.



capture.png (3.2 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.