BuZz
BuZz

Reputation: 17445

C# tooltip doesn't display long enough

I have a tooltip that is appearing on mouse hover on an image:

ToolTip tt = new ToolTip();
protected virtual void pictureBox_MouseHover(object sender, EventArgs e)
{
    tt.InitialDelay = 0;
    tt.SetToolTip(this.pictureBox, "Click 'LIVE ...");
}

My problem is that my text is rather long, and the tooltip disappears too fast. How can I get the tool tip to be displayed for longer?

Upvotes: 19

Views: 26797

Answers (6)

jetsquared
jetsquared

Reputation: 153

Unlike the answer described by Justin, I was not able to get the ToolTip to display for longer than the 5 seconds using the show method.

One of the other hangups I was having was the AutomaticDelay property. Long story short - if you want custom AutoPopDelay do not set AutomaticDelay.

Setting this property will automatically set... see MSDN:

AutoPopDelay = 10 x AutomaticDelay

InitialDelay = AutomaticDelay

ReshowDelay = (0.2) x AutomaticDelay

Here's code that worked for me:

ToolTip tt = new ToolTip();
private void someObjectName_MouseHover(object sender, EventArgs e) {
    tt = new ToolTip
    {
        AutoPopDelay = 15000,  // Warning! MSDN states this is Int32, but anything over 32767 will fail.
        ShowAlways = true,
        ToolTipTitle = "Symbolic Name",
        InitialDelay = 200,
        ReshowDelay = 200,
        UseAnimation = true
    };
    tt.SetToolTip(this.someObjectName, "This is a long message");
}

Bonus:

private void someObjectName_MouseLeave(object sender, EventArgs e)
    {
        tt.Active = false;
    }

Upvotes: 11

Sergey K
Sergey K

Reputation: 4114

Set the value of AutoPopDelayproperty

 tt.AutoPopDelay = 10000;

Upvotes: 9

LueTm
LueTm

Reputation: 2380

Doesn't seem to be mentioned. Setting ToolTipService.ShowDuration="20000" on the parent works for me. MSDN doesn't say but it's in milliseconds.

Upvotes: 0

Joel
Joel

Reputation: 21

I've found the following steps work for me:

Set the to 1/10 of your desired .

Then you can adjust your and your afterwards.

MSDN Link

Upvotes: 1

V4Vendetta
V4Vendetta

Reputation: 38210

ToolTip.Show(text, [control], time in milliseconds) is what you need i think

This will let you display your long text for a specific number of milliseconds. Also if you text is too long then you could inert NewLine in between the text so that its wrapped up and not shown as a long tooltip spanning across the form

Upvotes: 2

Justin
Justin

Reputation: 86729

Set the AutoPopDelay property to be something higher - it defaults to 5000 (5 seconds)

Update: My mistake:

The maximum time you can delay a popup is 5000 milliseconds. For longer durations, use the Show method to control the exact moment when the ToolTip is displayed.

So you can't get the tool tip to be displayed for longer than 5 seconds using this method - instead you need to use the Show to explicitly show the tool tip when the user hovers over the picturebox. Just replace your call to SetToolTip with one to Show in your MouseHover event handler:

ToolTip tt = new ToolTip();
protected virtual void pictureBox_MouseHover(object sender, EventArgs e)
{
    tt.Show("Click 'LIVE ...", this.pictureBox, 10000);
}

Upvotes: 21

Related Questions