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

Insert text and alignment

2 Answers 191 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rieni De Rijke
Top achievements
Rank 1
Rieni De Rijke asked on 19 Apr 2011, 08:50 PM
I want to insert some text, like in a usual letter: the date and "Dear John,"...

I tried this:
editor.Insert(DateTime.Now.Date.ToShortDateString());
editor.InsertLineBreak();
editor.Insert("Dear John,");
...and it works fine!

Now I want to have my date at the right and John at the left.
I tried this:
editor.Insert(DateTime.Now.Date.ToShortDateString());
editor.ChangeTextAlignment(RadTextAlignment.Right);
editor.InsertLineBreak();
editor.Insert("Dear John,");
editor.ChangeTextAlignment(RadTextAlignment.Left);

But it did not work out.
I searched the web for a little bit help about ChangeTextAlignment, but could not find something usefull.
I guess I have to use paragraphs, selection...?


2 Answers, 1 is accepted

Sort by
0
Accepted
Andrew
Telerik team
answered on 20 Apr 2011, 02:29 PM
Hi Rieni De Rijke,

You are using the right method here - ChangeTextAlignment(RadTextAlignment alignment). However it changes the alignment of the corresponding paragraph. So, if you want the date to be aligned right and "Dear, John..." to be aligned left, you should put them in separate paragraphs, as a line break just moves the caret to the next line, but not to the next paragraph. Actually, all you need to do is replace the editor.InsertLineBreak() with

this.radRichTextBox1.Insert(Environment.NewLine);
and everything should be fine.

If you have any other questions, fell free to contact us.

Greetings,
Andrew
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rieni De Rijke
Top achievements
Rank 1
answered on 21 Apr 2011, 07:35 PM
That's it!
Thank you very much!
Tags
RichTextBox
Asked by
Rieni De Rijke
Top achievements
Rank 1
Answers by
Andrew
Telerik team
Rieni De Rijke
Top achievements
Rank 1
Share this question
or