code:
public Form1()
{
InitializeComponent();
//全局只用一个ToolTip
ToolTip tp = new ToolTip();
listBox.MouseMove += (sender, e) =>
{
int index = listBox.IndexFromPoint(e.Location);
// 判断鼠标所在位置是否是有效元素
if (index != -1 && index < listBox.Items.Count)
{
// NodeInfo是自定义对象,ToString函数返回文件名,Location属性显示全部路径
NodeInfo nInfo = listBox.Items[index] as NodeInfo;
if (tp.GetToolTip(listBox) != nInfo.Location.ToString())
{//如果已经显示则不再显示,可防止闪烁
tp.SetToolTip(listBox, nInfo.Location.ToString());
}
}
};
}
原文地址:http://dr953393.blog.51cto.com/1968164/1860525