I want to add a horizontal line to the RichTextBox as a delimiter of my text.
I've found some examples of RTF code implementing a line and tried them in that way:
rtbResFile.Rtf = @"{\rtf1{\pard some text.\par}{\pard \brdrb \brdrs \brdrw10 \brsp20 \par}{\pard \par}{\pard some other text.\par}}";
This way implements creating a blank paragraph with border, so that should looks like a line. However it doesn't show anything. Just a blank paragraph.
Even if I try to implement it in the way include line object
{\rtf1
{\pard some text.\par}
{\pard {\*\do\dobxcolumn\dobypara\dodhgt
\dpline\dpxsize9200\dplinesolid\dplinew30}\par}
{\pard some other text.\par}
}
It still shows nothing. Does RichTextBox supports this? Or any other ways include the horizontal line in the rtf string?
Best Answer
There are a few different ways to create a horizontal line in RTF. Depending on the control or program being used your mileage may vary. RTF implementations in controls and programs tend to simply ignore markup that they don't know how to deal with.
By drawing polygons:
By inserting a blank paragraph with a border followed by another blank paragraph without a border:
You can change the size and apparent positionof the line by setting indents on the paragraph:
I highly recommend O'Reilly's RTF Pocket Guide for working with this stuff, which is where this came from.
Some further experimentation produced the code below, which does work in WordPad and the RichTextBox control.
Basically, it involves inserting a 1x1 pixel image of a black dot and stretching it as needed by adjusting the height and width goals. The goal measurement is in twips. A twip is defined as being 1/1440 of an inch. It's a horrible hack, but it works.