Search code examples
c#.netwinformsuser-interface

.NET Label.TextAlign seems not to work


I have a label that I want to right align to be able to place aligned to a text box.
The Designer in Visual Studio 2010 Express have generated this code for me

this.lblAddData.AutoSize = true;  
this.lblAddData.Location = new System.Drawing.Point(167, 452);  
this.lblAddData.Name = "lblAddData";  
this.lblAddData.Size = new System.Drawing.Size(25, 14);  
this.lblAddData.TabIndex = 5;  
this.lblAddData.Text = "text";  
this.lblAddData.TextAlign = System.Drawing.ContentAlignment.MiddleRight;  

[text][textbox] In the code I change the text programmaticly

lblAddData.Text = "a very long text";

but the text is hiding behind the texbox that I have placed next to the label on the
right side.

[a ver][textbox]

Have someone experienced the same problem before?
I know it is missing information so ask me if you need more info.
Best Regards
Görgen


Solution

  • Well, I spotted the error myself; AutoSize was set to true, that is default behavour

    this.lblAddData.AutoSize = true;
    

    When I changed this to false it worked as I assumed it should.