ToolTip from within a UserControl

H

Henry Padilla

I am making a UserControl that is entirely taken up by Labels. I have found
a way to pass the Click even to the outside (I have the same handler for
each label.click and that raises a this.OnClick(e); )

How do I do this with whatever mystery is the ToolTip component? Since the
UserControl surface is not exposed, it will never send the ToolTip whatever
it needs to fire. I've tried the OnMouseHover() I've tried looking for the
ToolTip component in the parent and then do a GetTooltip for the UserControl
but there is no guarantee that the Tooltip will get created and initialized
first.

Thanks for the help,
Tom P.
 
B

Bruce Wood

The easy way to handle this problem is to have your UserControl export
a ToolTop property that, when it's set, just sets the ToolTip
properties of all of its component controls. The get accessor can just
return the ToolTip from any component within the UserControl, as
they'll all be the same.

The only downside to doing it this way is that the tool tip will be
redisplayed whenever the user moves from one component to another
within the user control, so the tool tip can become annoyingly
persistent at times.

I remember someone else writing in
microsoft.public.dotnet.languages.csharp that they had solved this
problem a different way using MouseHover and timers, but I don't
remember the details. If I find that post again I'll post a link to it
here.
 
H

Henry Padilla

I don't have access to each label from the MainForm, they are private to
(obfuscated by) the UserControl.

That's the problem.

Tom P.
 
J

James Swindell

Your UserControl should not be concerned with the setting or displaying of a
tooltip. It's the job of the developer to instruct the control what text to
display when using the ToolTip component. If you want, you could always
just create a custom Hint property.
 
H

Henry Padilla

True but without being able to expose the magical ToolTip event my control
will never cause a tooltip to be displayed.

I think the custom property is the way I'm going to have to go. I'll try
naming it the same as the ToolTip property and see if I can accidentally
hijack the functionality.

Tom P.
 

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