private ToolTip tip = new ToolTip();
private void FirstWindow_Load(object sender, EventArgs e) //加载界面
{
tip.ToolTipTitle = "提示";
tip.ReshowDelay = 100;
tip.AutoPopDelay = 20000;
tip.ToolTipIcon = ToolTipIcon.Info;
tip.IsBalloon = false;
}
private Point pointView = new Point(0,0);//鼠标位置 外部存储变量
private void listView1_MouseMove(object sender, MouseEventArgs e)//listview 的MouseMove事件
{
ListViewItem lv = this.listView1.GetItemAt(e.X, e.Y);
if (lv != null)
{
if (pointView.X != e.X || pointView.Y != e.Y)//比较当前位置和上一次鼠标的位置是否相同,防止tooltip因MouseMove事件不停刷新造成的闪烁问题,
{
tip.SetToolTip(listView1, "双击进入 " + lv.SubItems[0].Text);
}
}
else
{
tip.Hide(listView1);//当鼠标位置无listviewitem时,自动隐藏tooltip
}
pointView = new Point(e.X,e.Y);//存储本次的鼠标位置,为下次得位置比较准备
}