Wilson Wilson - 1 year ago 97
C# Question

Programmatically adding Label to Windows Form (Length of label?)

In my code, i create a label with the following:

Label namelabel = new Label();
namelabel.Location = new Point(13, 13);
namelabel.Text = name;

The string called name is defined before this, and has a length of around 50 characters. However, only the first 15 are displayed in the label on my form. I tried messing with the MaximumSize of the label but to no avail.

Answer Source

Try adding the AutoSize property:

namelabel.AutoSize = true;

When you place a label on a form with the design editor, this property defaults to true, but if you create the label in code like you did, the default is false.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download