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

Aligning of contents inside richtext box

1 Answer 234 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
vikas
Top achievements
Rank 1
vikas asked on 31 Jul 2014, 04:20 PM
Hi,
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:RadRichTextBox.Document>
                    <telerik:RadDocument>
                        <telerik:Section>
                            <telerik:Paragraph FontSize="10">
                                <telerik:Span FontFamily="Arial" Text=" "  FontSize="10" />
                            </telerik:Paragraph>
                        </telerik:Section>
                    </telerik:RadDocument>
                </telerik:RadRichTextBox.Document>
            </telerik:RadRichTextBox>

Thanks,

1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 05 Aug 2014, 12:47 PM
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"));
left.Blocks.Add(p1);
row.Cells.Add(left);
 
TableCell center = new TableCell() { TextAlignment = RadTextAlignment.Center };
Paragraph p2 = new Paragraph();
p2.Inlines.Add(new Span("bbbbbb"));
center.Blocks.Add(p2);
row.Cells.Add(center);
 
TableCell right = new TableCell() { TextAlignment = RadTextAlignment.Right };
Paragraph p3 = new Paragraph();
p3.Inlines.Add(new Span("cccccccc"));
right.Blocks.Add(p3);
row.Cells.Add(right);
 
table.Rows.Add(row);
 
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.InsertTable(table);

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


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
vikas
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or