Tuesday, September 11, 2018

Make a WinForms label grow text right to left instead of left to right.

This was surprisingly painful to figure out. My solution looks like this:

this.toPath.AutoSize = false;
this.toPath.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.toPath.Location = new System.Drawing.Point(-1050, 308);
this.toPath.Name = "toPath";
this.toPath.Size = new System.Drawing.Size(1794, 23);
this.toPath.TabIndex = 10;
this.toPath.Text = "?";
this.toPath.TextAlign = System.Drawing.ContentAlignment.MiddleRight;

 
 

AutoSize must be false, TextAlight should be MiddleRight, and the Anchor set to Right. Beyond all that, you must drag out a long-sized box for the whole of the label as a box snugged up against minimalistic starting text, such as my question mark, will not grow outwards in the right direction.

No comments:

Post a Comment