Hi all,
Left of a TextBox I have a Label and the text changes during a run so I want the text to be right aligned. So I used the TextAlign property of a Label and set it to MiddleRight. It does not work. Looked for an answer, could not find one. Don't no what I am overlooking here:-/
Any reply is more than welcome.

Edited by ddanbe: n/a

7 Years
Discussion Span
Last Post by ddanbe

Yeah I submitted a bug report to Microsoft and they confirmed it was a bug, but not important enough to fix. :(


Hi DdoubleD and Scott,

Think I found another solution to the problem, I forgot about Label all the way and derived a class from Panel:

class LabelPanel : Panel
        public LabelPanel()
            text = string.Empty;
            font = new Font("Ariel", 8f);
            fontcolor = Color.Black;

        public string text { get; set; }
        public Font font { get; set; }
        public Color fontcolor { get; set; }
       //more or less properties here don't know yet

        protected override void OnPaint(PaintEventArgs e)
            Graphics G = e.Graphics;
            Brush brush = new SolidBrush(fontcolor);
            Rectangle rec = new Rectangle(new Point(0, 0), this.Size);
            StringFormat strfmt = new StringFormat();
            strfmt.Alignment = StringAlignment.Far; // means Right if RightLeft is true
            G.DrawString(text, font, brush, rec, strfmt);

And this is how I call it in a Form:

LabelPanel LP = new LabelPanel();
        public Form1()
            LP.Size = new Size(290, 20);

        private void SetLabelTexts(List<string> SL)
            LP.text = SL[0];
            //Many more LabelPanels here

Works like a charm!

Votes + Comments
Nice solution :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.