Click here to Skip to main content
15,881,850 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I right align a portion of text in a line in a RichTextBox during runtime?
Posted
Comments
Sergey Alexandrovich Kryukov 28-Feb-12 13:40pm    
"RichTextBox" is not a type. There are at least two different types with this name. Which one?
The answer would be different.
--SA

With System.Windows.Forms.RichTextBox, append to the Rtf code: string.Format("\qr {0}\par\", yourParagraphText); your text in the variable yourParagraphText will be appended as right-aligned. Or use another property, SelectedRtf, to insert in the middle.

Yes, stupid RTF coding, I know. I did it typing two paragraphs in WordPad, saving the file and looking at what's inside.

Without RTF row code, use the property System.Windows.Forms.RichTextBox.SelectionAlignment with a preliminary selected paragraph. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionalignment.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.horizontalalignment.aspx[^].

This was not nice of you not to indicate if you work with Forms or WPF. Now about WPF:

As to System.Windows.Controls.RichTextBox, you should do all the work with FlowDocument instead, and get a RichTextBox using the constructor RichTextBox(FlowDocument document), please see:
http://msdn.microsoft.com/en-us/library/ms597536.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.documents.flowdocument.aspx[^].

—SA
 
Share this answer
 
v3
Comments
Espen Harlinn 28-Feb-12 14:16pm    
Nice reply :)
Sergey Alexandrovich Kryukov 28-Feb-12 14:33pm    
Thank you, Espen.
--SA
you can make a selection and use HorizontalAlignment:

RichTextBox.SelectionAlignment = HorizontalAlignment.Right;

regards
bejituharo
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900