This is a migrated thread and some comments may be shown as answers.

RadDocument WPF - How to programatically create horizontal line?

1 Answer 164 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
C
Top achievements
Rank 1
C asked on 28 Jul 2014, 09:01 PM
How can I create a horizontal line similar to what is supported in Word in C# code programmatically without ever showing a RichTextBox control on screen.  We are using RadDocument to output read-only report data.

Also,  how can I do this without messing up the font before and after the table?  The fonts get reduced in size just before and after the table.

internal static void AddHorizontalLine(Section sec, RadDocument doc, double widthInches)
{
    //insert a horizontal line - table with 1 row and column - with a top border line and a table height of a few pixels
          
    Table t = new Table() {PreferredWidth = new TableWidthUnit(TableWidthUnitType.Fixed, Unit.InchToDip(widthInches)) };
    Border noBorder = new Border(BorderStyle.None);
    t.Borders = new TableBorders(noBorder, new Border(BorderStyle.Single), noBorder, noBorder);
    TableRow row = new TableRow();
    row.Height = 2.0;

TableCell cell = new TableCell();
cell.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 100.0);

Paragraph par = new Paragraph();
par.FontSize = 2;
par.Inlines.Add(new Span(" "));
cell.Blocks.Add(par);
row.Cells.Add(cell);

t.Rows.Add(row);

sec.Blocks.Add(t);

//We need to re-measure and re-layout the document after modifying the blocks, inlines, children and properties to format the output correctly. The fonts will be off if this is not done.
//doc.MeasureAndArrangeInDefaultSize(); //causes formatting problems in TOC
}

I've seen these two similar questions.
  http://www.telerik.com/forums/adding-an-horizontal-line-programatically
  http://www.telerik.com/forums/horizontal-line-ce12906b62c2

1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 31 Jul 2014, 12:12 PM
Hi,

Please find attached a simple example demonstrating how you can mimic a horizontal line in RadRichTextBox. Please note that tables in the context of RadDocument need to be surrounded by paragraphs.

As to your comment about the font size prior and after table, we are unaware of a reason for such behavior unless you've explicitly specified the font size needs to be small. If you are still experiencing this issue please provide more details on your setup or send us a sample application.

I hope this is useful.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
RichTextBox
Asked by
C
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or