tags:

views:

124

answers:

2

I'm using C#. Sometimes the text returned from a web service (which I display in a label) is too long and gets cut off on the edge of the form. Is there an easy way to add a newline to the label if it's not going to fit on the form?

Thanks

+4  A: 

If you set the label to AutoSize, it will automatically grow with whatever text you put in it.

In order to make it word wrap at a particular width, you can set the MaximumSize property.

myLabel.MaximimSize = new Size(100, 0);
myLabel.AutoSize = true;

Tested and works.

If you always want to be able to see the data, you can set the Label's container's AutoScroll property to true.

John Gietzen
+1, winner. Showing how to grow the form is what the OP forgot to ask.
Hans Passant
A: 

If the label control fails you, you can use a scrollable textbox instead.

Beth