RadDocument WPF - How to programatically create horizontal line?

2 posts, 0 answers
  1. C
    C avatar
    43 posts
    Member since:
    Jul 2014

    Posted 28 Jul 2014 Link to this post

    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(" "));



    //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.

  2. Petya
    Petya avatar
    989 posts

    Posted 31 Jul 2014 Link to this post


    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.

    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.
Back to Top