问题描述
假设我将LinkLabel控件添加到Windows窗体中,并在其中定义了两个不同的链接,如以下C#代码段所示:
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");
我最终在表单上贴上一个标签,标签上(看起来和行为类似)单击此处或此处".用户不知道链接的目标是什么,因此当鼠标悬停在任一链接上时,我想弹出一个工具提示以显示适当的URL.
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.
我正在以编程方式构建一个长文本包装的LinkLabel,因此只需将四个控件放置为"[Label:'Click'] [LinkLabel:'here'] [Label:'or'] [LinkLabel:'here']在表单上"以在不同的LinkLabel上独立分配ToolTipText并不是一个好选择.
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.
完成此任务的最佳方法是什么?还是我应该使用LinkLabel以外的其他东西?
What is the best way to accomplish this? Or, should I be using something other than a LinkLabel?
推荐答案
遗憾的是,我不认为这很容易,尽管LinkLabel有一个LinkClicked事件,该事件具有带有单击链接的事件参数,但是没有相应的LinkMouseHover/Enter事件,因此无法知道您位于哪个链接上.
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.
也许唯一的解决方案是彼此相邻创建许多LinkLabel,然后在每个LinkLabel上使用MouseHover来知道也指向了哪个链接.
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.
这篇关于为.NET LinkLabel控件的每个链接区域显示不同的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!