The label grows from right to left.

I have a shortcut in my form that is to the right of the form. This label loads dynamic text.

Sometimes the text that it loads is too long and the text crosses the border of the form, that is, some text comes out of the form.

I want the label to increase from right to left, and not from left to right. How to achieve this?

+47
c # winforms label
Apr 10 2018-11-11T00:
source share
5 answers

My problem was that my shortcut was in the panel and everything I did did not work.

I did to place the label in the TableLayoutPanel control and set the TableLayoutPanel RightToLeft property to True ; it did the trick.

+22
Apr 11 2018-11-11T00:
source share

I solved this by setting the label

AutoSize Property : false ,

TextAlign - MiddleRight ,

a Anchor to the right .

Please note that the size of the label itself does not grow with the text, but you can handle it by providing it with enough width to match the content. The visual effect is the same.

+53
Dec 16 '13 at 12:25
source share

You cannot force it to β€œgrow from right to left,” but you can assign it the Left property so that it does not exit the form:

 label1.Text = "some dynamic text here..."; if (label1.Right > this.Width) label1.Left = this.Width - label1.Width; 

If the design allows this, you can also double its height so that the text spans two lines.

+6
Apr 10 2018-11-11T00:
source share

You can use TableLayoutPanel or another compatible container control, but instead set the RightToLeft property for the container set by Dock = "Right" for the label

The value of the RightToLeft property does not always give the expected results, since for some string formats the string changes, changing the word order.

+3
Apr 12 '13 at 4:43
source share

you can write it:

  public enum Leftorright { left,right} private Leftorright _LeftToRight = Leftorright.left; public Leftorright LeftToRight { get { return _LeftToRight; } set { _LeftToRight = value; } } protected override void OnTextChanged(EventArgs e) { int oldWidth; oldWidth = this.Width; base.OnTextChanged(e); if (LeftToRight == Leftorright.right && this.Width != oldWidth) { this.Left = this.Left - this.Width + oldWidth; } } 
+1
Dec 23 '14 at 8:28
source share



All Articles