0

I am creating a label in c# (random text, just as an example):

Label lblText = new Label();
lblText.Text = "A computer is a general purpose device that can be programmed to carry out a set of arithmetic or logical operations. Since a sequence of operations can be readily changed, the computer can solve more than one kind of problem.";
lblText.Location = new Point(48, 95);

But when it is displayed I can only see: "A computer is a"

How can I display the entire text?

EDIT: AutoSize worked, but it goes beyond the window's border, is there anything like "autoNewLine"? to keep the text inside the window

user990635
  • 3,979
  • 13
  • 45
  • 66

3 Answers3

3

Have a look at Label.AutoSize.

Gets or sets a value indicating whether the control is automatically resized to display its entire contents. [...] When added to a form using the designer, the default value is true. When instantiated from code, the default value is false.

If you also want to have word-wrapping, have a look at this question.

Quoting John Gietzen's answer:

If you set the label to AutoSize, it will automatically grow with whatever text you put in it. (This includes vertical growth.) If you want to make it word wrap at a particular width, you can set the MaximumSize property.

myLabel.MaximumSize = new Size(100, 0);
myLabel.AutoSize = true;
Community
  • 1
  • 1
germi
  • 4,628
  • 1
  • 21
  • 38
1

You need to set this property lblText.AutoSize = True; to true because it's created at runtime and will have a false a s default value

   Label lblText = new Label();    
    lblText.AutoSize = True;
    lblText.Text = "A computer is a general purpose device that can be programmed to carry out a set of arithmetic or logical operations. Since a sequence of operations can be readily changed, the computer can solve more than one kind of problem.";
    lblText.Location = new Point(48, 95);
BRAHIM Kamel
  • 13,492
  • 1
  • 36
  • 47
0

That is because the Width property of your TextBox is not high enough. Increase the Width of the TextBox and the rest of your text will automagically appear.

You can also make a TextBox auto-size to the right width by setting the lblText.AutoSize property to true.

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76