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

2019-06-14 16:46发布

问题:

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");
      } 
   }    
}


标签: c# tooltip