问题
So here is my file label. If the label is too long, it will go off the screen thus making me have to scroll.
I've tried the following properties (separate times):
RightToLeftas YesContentAlignmentas BottomRight or TopRight
However, none of them are working. What is the correct property?
回答1:
Try setting AutoSize to false (that makes a fixed size box). Then you can use the TextAlign property to align the text - e.g. use MiddleRight. That should do the trick.
回答2:
Label label = new Label();
label.AutoSize = false;
label.TextAlign = ContentAlignment.MiddleRight;
回答3:
Just Remove the autosize = true and set RightToLeft = true
and the label will now grow to the left.
回答4:
Yes AutoSize = false and RightToLeft = true will work. Note that when you set RightToLeft, the strange c# 2010 TextAlign TopLeft becomes aligned correctly to the right. If I set that to Top/Middle Right, the text jumps to the left instead!
回答5:
Sample (WPF):
Label label = new Label();
label.HorizontalContentAlignment = HorizontalAlignment.Right;
回答6:
This worked for me:
your_label_name.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
回答7:
All you have to do to label to make it work:
Textalign = MiddleRightAnchor = top and right
回答8:
Set Autosize=true and Textalign=MiddleRight.
来源:https://stackoverflow.com/questions/21218729/how-do-i-align-my-text-in-a-label-to-the-right-side