Pregunta

I have a Tooltip with the ShowAlways property set to true.

On the controls where I want the tooltip to display (LinkLabels in this instance), I see there is a "ToolTip on <name of my Tooltip>" property which expects a string.

However, my tooltip is shared between 5 LinkLabels, and should differ depending on which one is hovered over.

I do have a shared click event that works:

private void linkLabelPlatypus1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    int Platypus = 1;
    LinkLabel ll = null;
    if (sender is LinkLabel)
    {
        ll = sender as LinkLabel;
    }
    if (null != ll)
    {
        if (ll.Name == linkLabelPlatypus2.Name)
        {
            Platypus = 2;
        } else if (ll.Name == linkLabelPlatypus3.Name)
        {
            Platypus = 3;
        } else if (ll.Name == linkLabelPlatypus4.Name)
        {
            Platypus = 4;
        } else if (ll.Name == linkLabelPlatypus5.Name)
        {
            Platypus = 5;
        }
        toolTipPlatypi.SetToolTip(ll, DuckbillData.GetPlatypusDataForToolTip(Platypus)); 
    }
}

...but I want the tooltips to also show on hover, and not require the user to click the label.

¿Fue útil?

Solución

You should write a event handler for Mouse Hover and have your tool tip display logic inside it.

    private void Label1_MouseHover(object sender, System.EventArgs e) 
    {
       //display logic
    }

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mousehover.aspx

Otros consejos

You only need to set the tooltip once :

public Form1()
{
    InitializeComponent();

    toolTip1.SetToolTip(linkLabel1, "foo");
    toolTip1.SetToolTip(linkLabel2, "bar");
}

Done.

Doing this in a MouseHover or MouseEnter handler will call this function over and over each time the event fires. It will work, but it is unnecessarily complicated.

You only need one ToolTip on a form to provide tips for any number of components and it can provide them all simultaneously and continuously (ie: you don't have to change it or set it each time). Each component can have only one tip, but you can change it throughout the program any time you like. ShowAlways does not have to be true - it is used to make tooltips show on forms which are not active (ie: hover over an inactive window behind one with focus, etc).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top