views:

2231

answers:

2

Hello Everyone

To fullfill a requirement I have to show a tooltip manually for 30 seconds. According to msdn I just have to use the "Show" method.

toolTip.Show(QuestionHelpText, btnHelp, 30000);

But I only get the standard tooltip behavior, meaning that the message appears half a second after my click (only because the mouse pointer is still over the button). I tried some variations like

toolTip.Show(QuestionHelpText, btnHelp);

but still, nothing happens.

Does anybody have an idea why that is?

Thanks

A: 

Where is "toolTip" declared?

MSDN doesn't indicate (on the ToolTip.Show Method documentation) that the Show method is a blocking call, so if you're declaring toolTip in a method and then pretty much straight afterwards exiting the method then toolTip will have fallen out of scope, causing it to not render or disappear.

Rob
The tooltip is used on the usercontrol, so declared within the InitializeComponent
lostiniceland
+4  A: 

I know a simple workaround

Put a lable (let's name it labelHelp) with empty text near your button

The following code should work

    private void btnHelp_Click(object sender, EventArgs e)
    {
        toolTip.Show(QuestionHelpText, labelHelp, 3000);
    }
Bogdan_Ch
why does it work on the label, but not on the button?
lostiniceland
it will work for any control. Rob said correct that toolTip.Show is blocking method. so when it is used inside an event handler (i.e. inside btnHelp_Click) of the same control, it will not work as expected. the trick is to call toolTip.Show for a different control. The other workaround solution could be to have a timer and start toolTip.Show asyncroneosuly (for example in btnHelp_Click you start the timer for 0.1 sec, and then call toolTip.Show in a timer event). Using 2nd control looks like an easiest workaround for me.
Bogdan_Ch
thanks. now this is clear
lostiniceland