Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label grow from right to left

I have a label on my form which is on the right of the form. This label loads a dynamic text.

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

I want to make the label to grow from right to left instead of left to right. How do I achieve this?

like image 247
Yash Avatar asked Apr 10 '11 13:04

Yash


4 Answers

I solved this by setting the label

AutoSize property to false,

TextAlign to MiddleRight,

an Anchor to the right.

Notice that the label size itself is not growing with the text, but you can handle it by giving it enough width to fit the content. The visual effect is the same.

like image 132
Alejandro del Río Avatar answered Nov 17 '22 07:11

Alejandro del Río


My problem here was that my label was in a panel, and anything I did wasn't working.

What I did was to place the label in a TableLayoutPanel control and set the TableLayoutPanel's RightToLeft property to True; this did the trick.

like image 41
Yash Avatar answered Nov 17 '22 07:11

Yash


You can't make it "grow from right to left", but you can assign it's Left property so that it won't go out of the form:

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

If the design allows it, you can also double its height so that the text will span two lines.

like image 6
Shadow Wizard Hates Omicron Avatar answered Nov 17 '22 05:11

Shadow Wizard Hates Omicron


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

Setting RightToLeft property does not always give the expected results as for some string formats the string is modified changing the order of the words.

like image 6
armadillo.mx Avatar answered Nov 17 '22 07:11

armadillo.mx