-1

I use c# and I made an application. In the application, there is a label and when i try to print a text that is greater than 17 length, it only shows me the first 17 characters. Here is the code:

Label lbl = new Label();
lbl.ForeColor = Color.White;
this.Controls.Add(lbl);
this.BackColor = Color.Black;
lbl.Location = new Point(25, 25);
lbl.Text = "Welcome to The Application. This is an example!";
DavidG
  • 113,891
  • 12
  • 217
  • 223
  • 2
    Does this answer your question? [Word wrap for a label in Windows Forms](https://stackoverflow.com/questions/1204804/word-wrap-for-a-label-in-windows-forms) – Sinatr Aug 06 '21 at 13:28
  • 1
    The screenshot would be nice. I thought the text doesn't fit the form width. – Sinatr Aug 06 '21 at 13:36
  • If label is not AutoSized, you need to use wrapping and adjust width as desired and height as expected for a maximum, or calculate them dynamically using font properties at runtime. –  Aug 06 '21 at 13:40

1 Answers1

1

When you say print, I assume you mean display. I would guess that the label is too short and AutoSize property is set to false.

David.Warwick
  • 620
  • 1
  • 9
  • 28
  • 1
    You are seems to be right - "When added to a form using the designer, the default value is true. When instantiated from code, the default value is false" (from [Label.AutoSize](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.label.autosize)). – Sinatr Aug 06 '21 at 13:34
  • I didn't know that. I almost always use the GUI to add labels, so I thought the default was always true. I just assumed that somewhere in his code, he was setting it to false. – David.Warwick Aug 07 '21 at 00:37