The most obvious way to right-align a Label
in WinForms doesn\'t work: setting anchor to Top/Bottom Right and TextAlign to TopRight. If the text changes the lab
Well as Sphax noticed you have to:
AutoSize
to falseTextAlign
to Right, for example to MiddleRight
MeasureString
Code:
label.AutoSize = false;
label.TextAlign = ContentAlignment.MiddleRight;
int yourWidthHere = 100;
using (Graphics g = label.CreateGraphics())
{
SizeF size = g.MeasureString(text, label.Font, yourWidthHere);
label.Height = (int)Math.Ceiling(size.Height);
label.Text = text;
}