在C#.net 4.0中使用工具提示

我的问题是,对于listBox特定值,是否可以从数据库中获取某些值以显示为tooltip

场景:

我在listBox有几个项目,例如红色,黄色,白色。

当我选择/带鼠标箭头/聚焦在任何一个项目附近时, tooltip必须显示…例如,如果是红色,则tooltip应显示“原色”,如果是“黄色”,则tooltip应显示“二级色” ”。

我已经存储了“原色”,“二次色”,…,聚焦时必须显示的tooltip ,在数据库中。

我的问题是,对于listbox特定值,是否可以从数据库中获取某些值以显示为tooltip

您可以通过将此方法挂钩到列表框的鼠标移动事件来执行此操作

 using System.Windows.Forms; private void onMouseMove(object sender, MouseEventArgs e) { if(sender is ListBox) { ListBox listBox = (ListBox)sender; Point point = new Point(eX, eY); int hoverIndex = listBox.IndexFromPoint(point); if(hoverIndex >= 0 && hoverIndex < listBox.Items.Count) { ToolTip tt = new ToolTip(); tt.SetToolTip(listBox, "GetYourCustomTooltiphere"); } } }