问题
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