Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
120 views
in Technique[技术] by (71.8m points)

c# - How to justify text in a label

I have a label that displays on more than a line and I would like to justify the text in it (align left and right). What is the best way to achieve that?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Unfortunately only the three most basic and simple types of alignment are supported: Right, Left and Center.

The fourth one, Justified or Block, is not supported in any .NET control afaik, not even in a RichtTextBox :-(

The only workaround would be to add either spaces or better a smaller whitespace character like thin space(U+2009) or hair space (U+200A) between the words i.e. after the regular spaces until the Label's Height changes. Then step one back and try to find the next insertion point, i.e. the next line and so on.. until the end of the text is reached.

A little tricky but not terribly hard.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...