How do I align my text in a label to the right side?

徘徊边缘 提交于 2019-12-08 14:30:15

问题


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):

  • RightToLeft as Yes
  • ContentAlignment as 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:

  1. Textalign = MiddleRight
  2. Anchor = 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!