Displaying a different tooltip for each link area

2019-07-10 21:51发布

Suppose I add a LinkLabel control to a Windows form and define two different links in it, as with this C# snippet:

LinkLabel ll = new LinkLabel();
Controls.Add(ll);
ll.Text = "Click here or here";
ll.Links.Add(6, 4, "http://example.one");
ll.Links.Add(14, 4, "http://example.two");

I end up with a label on my form that says (and looks and behaves like) "Click here or here". The user doesn't know what the targets for the links are though, so I'd like to have a tooltip pop up showing the appropriate URL when the mouse is hovered over either one.

I am building a long, text-wrapped LinkLabel programmatically, so simply placing four controls as "[Label:'Click'] [LinkLabel:'here'] [Label:'or'] [LinkLabel:'here']" on the form to assign ToolTipText independently on the different LinkLabels is not a good option.

What is the best way to accomplish this? Or, should I be using something other than a LinkLabel?

1条回答
beautiful°
2楼-- · 2019-07-10 22:30

Sadly I don't think this is easy as although LinkLabel has a LinkClicked event which has an event argument with the clicked link, there's no corresponding LinkMouseHover/Enter event, so there's no way of knowing what link you are positioned over.

Perhaps the only solution would be to create many LinkLabels next to each other, and then use the MouseHover on each LinkLabel to know what link has been pointed too.

查看更多
登录 后发表回答