Quote Originally Posted by boops boops View Post
I have some comments on that.

Firstly, I wouldn't declare multiple tooltips insided the loop. You can't access those tooltips from elsewhere, e.g. if you want to allow the user to disable tooltips, because the identifier "tip" goes out of scope at the end of the loop. Besides, it's inelegant when one tooltip will do the same job for all the controls on the form.

More problematic is putting the loop inside a MouseHover event handler. The event could fire thousands of times during the lifetime of your application. That means each control will end up with thousands of tooltips to render, one on top of another. (You can check that this is true by defining 2 tooltips for the same control and giving the first one a longer text than the second one. At runtime you will see the first tooltip poking out behind the second one, meaning both tooltips are drawn.) What is more, the Garbage Collector won't be able to get rid of all those tooltips, even though they are out of scope, because they are attached to controls. It would be quite a burden on your application's performance, and it's so unnecessary when you actually only need one tooltip per form.

There may be scenarios where you might think of using more than one tooltip object (for example, one per user language), although I expect there would be better ways of doing the job with just one.

Finally, you could make your code a bit more compact if you want by replacing the loop beginning For Each ctrl As Control ... with this:
Code:
For Each ctrl As Control In tPage.Controls.OfType(Of GroupBox)
        tip.ToolTipTitle = ctrl.Text
        '... etc.
Next
BB
It doesn't seem to run more than once. I have call the method on load.