Automatically Wrap Text in Label

Y

Yaakov

I have the following scenario: I have a TableLayoutPanel in my form. In
one of the cells I want to place a Label control to display some text.
The label might have just a few words. It might have a paragraph. I
would like the label text to automatically wrap inside the cell in the
TableLayoutPanel. If the row in the TLP is not large enough, it should
automatically grow so that it can display all of the text.

1) I have tried setting Dock:Fill and AutoSize:False on the label. This
will cause the text in the label to wrap, but it will not grow past the
size of the cell in the TLP. If I set the row in the TLP to be
AutoSize, the whole row becomes hidden.

2) If I set it to Dock:Top, AutoSize:False, and set the TLP row to
AutoSize, this works, as long as the height of the Label is set to a
value sufficient enough to hold all of the text. But if the height is
not big enough, the text gets cut off.

In case 2 above, it seems like I am on the right track, and that it
would work if I had some way of dynamically making the Label taller
depending on whether it still needed to wrap the text.

Any suggestions for me on how I can accomplish this?
 
B

Bill Angus

Label control is not designed for this. Better to use a textbox control which has a possibility of scrollbars and a few other bits of functionality that you will need.... The backcolor and forecolor of the textbox can be set to any color you like, and the text-box disabled parameter can be set to true if you want it to look like a label control and to be read-only. Just make sure to change the forecolor text for your text control when it is disabled to something that you like and is not grey :)

Bill Angus, MA
http://www.psychtest.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top