1、首先,在工具箱中将ToolTip控件拖入到Winform界面下方。

2、接着,在指定的ListBox添加:XXX_MouseMove事件(如已添加则忽略此步)。其中:XXX为您的控件名称。

3、在该事件中添加如此代码:

         

int index = listBoxPhotos.IndexFromPoint(e.Location);
if (index != -1 && index < listBoxPhotos.Items.Count)
{
if (toolTip1.GetToolTip(listBoxPhotos) != listBoxPhotos.Items[index].ToString())
{
toolTip1.SetToolTip(listBoxPhotos, listBoxPhotos.Items[index].ToString());
}
}

OK。

最终代码类似于:

     

private void listBoxPhotos_MouseMove(object sender, MouseEventArgs e)
{
int index = listBoxPhotos.IndexFromPoint(e.Location);
if (index != -1 && index < listBoxPhotos.Items.Count)
{
if (toolTip1.GetToolTip(listBoxPhotos) != listBoxPhotos.Items[index].ToString())
{
toolTip1.SetToolTip(listBoxPhotos, listBoxPhotos.Items[index].ToString());
}
}
}