Aligning of contents inside richtext box

2 posts, 0 answers
  1. vikas
    vikas avatar
    11 posts
    Member since:
    May 2011

    Posted 31 Jul 2014 Link to this post

    The below code is used to give the user the option for adding formatted text. Like in excel, when the user is adding contents to right footer, the cursor starts from the right. Similarly, i want the cursor to start from the right for the below text box.

    For the center footer text box, the contents should get aligned center. Please help me in this regard.

     <telerik:RadRichTextBox Grid.Row="1" Grid.Column="0"  HorizontalAlignment="Left" Name="TxtRightFooterBox" IsSpellCheckingEnabled="False" IsContextMenuEnabled="False" IsSelectionMiniToolBarEnabled="False"
                                        DocumentInheritsDefaultStyleSettings="True"  GotFocus="TxtRightFooterBox_OnGotFocus" Visibility="Visible" Width="175" Height="125" Margin="5">
                                <telerik:Paragraph FontSize="10">
                                    <telerik:Span FontFamily="Arial" Text=" "  FontSize="10" />

  2. Petya
    Petya avatar
    990 posts

    Posted 05 Aug 2014 Link to this post

    Hi vikas,

    RadRichTextBox's concept of headers and footers is rather different from the one of MS Excel, so there is no way to specify separate left/right/center footers and align them out of the box. There are, however, several alternative approaches which you can adopt.

    1. Add tab stops to the paragraph in the header/footer, so that content is aligned right, left and center. For example, the following does this in the default header of a document:
    if (this.radRichTextBox.Document.Sections.First.Headers.Default.Body == null)
        this.radRichTextBox.Document.Sections.First.Headers.Default.Body = new RadDocument();
    RadDocumentEditor documentEditor = new RadDocumentEditor(this.radRichTextBox.Document.Sections.First.Headers.Default.Body);
    documentEditor.AddTabStop(new TabStop(TabStopType.Left, 10));
    documentEditor.AddTabStop(new TabStop(TabStopType.Center, 289));
    documentEditor.AddTabStop(new TabStop(TabStopType.Right, 614));
    documentEditor.InsertInline(new Span("aaaaa" + FormattingSymbolLayoutBox.TAB + "bbbbb" + FormattingSymbolLayoutBox.TAB + "cccccc"));

    2. Place a table containing three cells in the footer and specify the alignment of each cell to left, center and right respectively. 
    Table table = new Table();
    TableRow row = new TableRow();
    TableCell left = new TableCell() { TextAlignment = RadTextAlignment.Left };
    Paragraph p1 = new Paragraph();
    p1.Inlines.Add(new Span("aaaa"));
    TableCell center = new TableCell() { TextAlignment = RadTextAlignment.Center };
    Paragraph p2 = new Paragraph();
    p2.Inlines.Add(new Span("bbbbbb"));
    TableCell right = new TableCell() { TextAlignment = RadTextAlignment.Right };
    Paragraph p3 = new Paragraph();
    p3.Inlines.Add(new Span("cccccccc"));
    if (this.radRichTextBox.Document.Sections.First.Headers.Default.Body == null)
        this.radRichTextBox.Document.Sections.First.Headers.Default.Body = new RadDocument();
    RadDocumentEditor documentEditor = new RadDocumentEditor(this.radRichTextBox.Document.Sections.First.Headers.Default.Body);

    I hope this is useful. Let me know if you need additional assistance.

    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