usage of tooltip in C#.net 4.0 [closed]

时间秒杀一切 提交于 2019-12-23 06:15:09

问题


My question is whether is it possible to fetch some values from database to show as a tooltip, for particular values in listBox?

Scenario:

I have few items in listBox,say for example red, yellow, white.

When i select / bring my mouse arrow / focused near any one of the item , the tooltip must display..for example, if red, then tooltip should display "primary color", if "yellow" ,then tooltip should display "secondary color".

I had stored the "primary color","secondary color",.. , the tooltip that must be showed when focused, in the database.

My question is whether is it possible to fetch some values from database to show as a tooltip, for particular values in listbox?


回答1:


You can do this by hooking this method to mouse move event of your listbox

using System.Windows.Forms;

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


来源:https://stackoverflow.com/questions/17771973/usage-of-tooltip-in-c-net-4-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!