Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How i can align text in textbox or richtextbox like this:
word:             1
word2:            2
word3:            3
word4:            4
superlongword:    5
otherword:        6
abc:              7

i tried to add tabulation symbol after word, but this is working well, if all words have same length.
any ideas?
Posted
Updated 25-Feb-15 5:17am
v2
Comments
Sergey Alexandrovich Kryukov 25-Feb-15 11:28am    
Of course using tab is totally wrong. Wasn't it apparent from the very beginning? You can to use selection formatting.
—SA
Arlert 25-Feb-15 11:30am    
in richtextbox i will be able to apply alignment for whole paragraph, but with textbox such operation can not be done, no?
Sergey Alexandrovich Kryukov 25-Feb-15 11:40am    
Of course it can be done. Have you seen Solution 1?
—SA

1 solution

Please see my comment to the question.

This is how you can do it in XAML: http://www.wpf-tutorial.com/rich-text-controls/richtextbox-control[^].

To format some part of the document on the fly, you need to obtain some text range, System.Windows.Documents.TextRange: https://msdn.microsoft.com/en-us/library/system.windows.documents.textrange%28v=vs.110%29.aspx[^].

As you can see from the inheritance diagram, it can be, for example, selection.

Now you can apply some formatting for the range (which can be applicable or not; in your case, it has to be some block element, such as a paragraph). You will find the way to do it here: https://msdn.microsoft.com/en-us/library/system.windows.documents.textrange.applypropertyvalue%28v=vs.110%29.aspx[^].

Look at the code sample at the end.

—SA
 
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