CheckedListBox 项目的工具提示?
当用户将鼠标悬停在 CheckedListBox 中的项目上时,是否有一种直接的方法可以设置附加文本显示在工具提示中?
我期望能够在代码中做的是:
uiChkLstTables.DisplayOnHoverMember = "DisplayOnHoverProperty"; //Property contains extended details
任何人都可以为我指出正确的方向吗? 我已经找到了几篇文章,其中涉及检测鼠标当前位于哪个项目上并创建新的工具提示实例,但这听起来有点过于做作,不是最好的方法。
提前致谢。
Is there a straighforward way to set additional text to appear in a tooltip when a user's mouse is held over an item in a CheckedListBox?
What I would expect to be able to do in code is:
uiChkLstTables.DisplayOnHoverMember = "DisplayOnHoverProperty"; //Property contains extended details
Can anyone point me in the right direction to do this? I've already found a couple of articles that involve detecting which item the mouse is currently over and creating a new tooltip instance, but this sounds a little too contrived to be the best way.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将 Tooltip 对象添加到表单中,然后为调用 ShowToolTip() 方法的 CheckedListBox.MouseHover 添加事件处理程序;
添加 CheckedListBox 的 MouseMove 事件,其代码如下:
然后创建 ShowToolTip 方法:
Add a Tooltip object to your form and then add an event handler for the CheckedListBox.MouseHover that calls a method ShowToolTip();
Add MouseMove event of your CheckedListBox which has the following code:
Then create the ShowToolTip method:
或者,您可以使用
ListView
改为复选框。 该控件有内置支持工具提示。
Alternately, you could use a
ListView
with checkboxes instead. This control hasbuiltin support for tooltips.
我想扩展费明的答案,以便也许使他的精彩解决方案更加清晰。
在您正在使用的表单中(可能在 .Designer.cs 文件中),您需要将 MouseMove 事件处理程序添加到 CheckedListBox(Fermin 最初建议使用 MouseHover 事件处理程序,但这对我不起作用)。
接下来,向表单添加两个类属性,一个 ToolTip 对象和一个整数,以跟踪显示工具提示的最后一个复选框。
最后,您需要实现 showCheckBoxToolTip() 方法。 这个方法与Fermin的答案非常相似,只不过我将事件回调方法与ShowToolTip()方法结合起来。 另请注意,方法参数之一是 MouseEventArgs。 这是因为 MouseMove 属性需要 MouseEventHandler,然后由 MouseEventArgs 提供。
I would like to expand upon Fermin's answer in order to perhaps make his wonderful solution slightly more clear.
In the form that you're working in (likely in the .Designer.cs file), you need to add a MouseMove event handler to your CheckedListBox (Fermin originally suggested a MouseHover event handler, but this did not work for me).
Next, add two class attributes to your form, a ToolTip object and an integer to keep track of the last checkbox whose tool tip was shown
Finally, you need to implement the showCheckBoxToolTip() method. This method is very similar to Fermin's answer, except that I combined the event callback method with the ShowToolTip() method. Also, notice that one of the method parameters is a MouseEventArgs. This is because the MouseMove attribute requires a MouseEventHandler, which then supplies MouseEventArgs.
在项目的复选框列表中运行 ListItems,并将适当的文本设置为项目“标题”属性,它将在悬停时显示...
Run through your ListItems in your checkbox list of items and set the appropriate text as the item 'title' attribute, and it will display on hover...
做作与否; 这就是……
我不知道有比您已经描述的更简单的方法(尽管我可能会重复使用工具提示实例,而不是一直创建新的实例)。 如果您有文章展示了这一点,那么请使用它们 - 或使用本机支持此功能的第三方控件(没有想到)。
Contrived or not; that's what there is...
I'm not aware of an easier way than you have already described (although I'd probably re-use a tooltip instance, rather than creating new all the time). If you have articles that show this, then use them - or use a 3rd party control that supports this natively (none leap to mind).