By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,576 Members | 1,799 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,576 IT Pros & Developers. It's quick & easy.

Need to resize label height automatically.

P: n/a
I am using a label as a tooltip box because I need to be able to change the
background of the box depending on the information it is representing.

That aside, I need to be able to auto-size the box depending on the amount
of data within it.

Sometimes the text in the label will be single-line, but a little long where
it needs to wrap.
Sometimes the text in the label has been forced to spread over three lines.
Sometimes the label has only one lshort text string.

The problem is that the Autosize property only affects the width of the
label, and I need it to resize to reasonable dimensions.
I do not want a very long tooltip spanning the entire screen when it could
wrap round to three shorter lines in a box.
I do not want the text in the box to become truncated because the box isn't
big enough.

So please, can anyone come up with a sensible and effective means of scaling
a label (or alternative control) so that the data within is displayed in a
box representing a 5:4 ratio or thereabouts?

Thanks in advance for any feedback. Newsgroup replies only please.

Feb 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"ngreplies" <ng*******@voidtdrd.freeserve.co.uk> wrote in message
news:ds**********@news6.svr.pol.co.uk...
I am using a label as a tooltip box because I need to be able to change the
background of the box depending on the information it is representing. The problem is that the Autosize property only affects the width of the
label, and I need it to resize to reasonable dimensions. So please, can anyone come up with a sensible and effective means of
scaling a label (or alternative control) so that the data within is
displayed in a box representing a 5:4 ratio or thereabouts?


There's probably a cleverer way these days, but when I've done things
like this I've let the Label size itself initially, then dragged it back
width-wise, kicking and screaming, until it gets to a ratio I'm happy with
- IIRC, as you "squash" it horizontally, it will grow vertically by itself.

It's probably best to do this on a non-visible Label, then copy the Text
and Size properties over to your tooltip Label (which no longer needs
to be AutoSize'd), something like

With lblAutoSizer
.Text = ...

Do While ( .Width / .Height ) > ( 5 / 4 )
.Width = CInt( .Width * 0.9 )
Loop

lblToolTip.Text = .Text
lblToolTip.Size = .Size
End With

HTH,
Phill W.
Feb 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.