auto sizing controls anyone?

kletkeman

Newcomer
Joined
Feb 16, 2003
Messages
3
In VB6, I was able to create a nice little CornerTip class that used a label control to contain multi-line text and then set the form's size to match the label (plus a small fudge factor.) This allowed me to use a simple interface and get alert windows that were just the right size. Way cool.

Now ... in .NET, the label control does not appear to handle multi-line text. And the textbox only auto sizes for single lines.

I'm wondering if someone out there has discovered an easy solution to this issue? Is there a multi-line, auto-sizing control available for text output?
 
The .NET label control supports multiline text just fine. If you tell it to autosize it will only base its size on one line of text though, how would it know what width it should be otherwise? This is how the VB6 one behaved too if I remember correctly.
 
I think you'll find that the VB6 implementation of the label control sized itself perfectly, while the VB.NET label control sizes to only one line. The attached zip file contains a VB6 project that demonstrates this property. The .NET subdirectory contains the converted solution, and it does not work correctly. Well ... I suppose it works correctly according to Microsoft, just not correctly according to any application that required this behavior.

I find it most unfortunate that this control has been broken. Worse, the multiline capability in the textbox is similarly broken. There is, in fact, no control available to do what I want to do without massive work on my part.

I'd use the tooltip control, but it needs to be bound to the form's various controls, and I want my tooltips to float above individual nodes in a TreeView.
 

Attachments

You're quite right, the .NET one doesn't expand itself vertically when you insert linebreaks with autosize on. I wonder why.

Here's a couple of tips though - firstly, don't ever use the upgrade wizard. It is a menace, and a waste of space. It teaches notoriously bad coding habits, and makes use of a special library for functions similar to VB6 ones when you should be rewriting in proper .NET code.

Secondly, if you really need this behaviour you have all the power of GDI+ available for measuring and drawing text, you do not need to use a Label control to achieve the effect.
 
While I agree that GDI+ provides everything I need to create the ultimate floating multi-line tooltip, I was able to do it in a few lines of code in VB6. Now I have to get into text sizing etc, which is not a part of the project I'm doing. So by no longer getting it essentially for free, I'm simply going to dumb down the feature (display on one line for now ... yuck.)

It's a minor ommission for Microsoft, but one they really did not need to do. Some clever coder no doubt reused the text box class implementation without regard to backward compatibility. Class inheritance is a wonderful thing, until someone comes along and decides that everything has to behave the same. Bummer.

P.S. I used the upgrade wizard just to make this demonstration project quickly. I agree that it is evil and should be avoided unless absolutely necessary. No need to cart around legacy objects if you can avoid it.
 
Back
Top