position (and resize) 2 labels dynamically within a container (xpander control)

B

Bonna

Hi,

I have 2 label within a xpander control. (or another container for that
matter)

The contents of the labels are set dynamically (label.Text = ...).
I want to use a fixed width (the width of the container), but the label has
to span its text across multiple lines. (so the height is variable).

It is important to know the height of the first label, since I want to
position my second label just underneath it.
(secondlabel.top = firstlabel.top + firstlabel.height + 5px)

The problem is that when the first label receives new data (I've set the
label.Autosize property to true), it changes it's width to the text lenght
but doesn't span accross multiple lines...(so now the text is clipped in the
border) and therefore doesn't adjust the label.width property.
I assume this is because the labelcontrol doesn't know the boundaries of
it's container??

How do you resize the label at runtime? Can you set some kind of max. width
while still using autosize? Am I overlooking a property here?

Thanks in advance!

Bonna
 
L

Les Smith

Autosize on a label control only changes the length of the
control based on the contents of the Text property. The
height is affected by the FontSize.

If you want increase the length and the height of the
label, you must estimate the size by the number of
characters in the text and do the resizing with code.


Hope this helps.

Articles, free code, books, general .NET info, add-ins at
http://www.knowdotnet.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