110,534
社区成员
发帖
与我相关
我的任务
分享
#region 提示悬浮窗
int x = 0, y = 0;
string str_tip="";
private void datagv_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
//判断选择单元格是否有效
if (e.RowIndex < 0 || e.ColumnIndex < 0)
{
return;
}
int i = e.ColumnIndex;//获取鼠标停留的列索引
int ei = e.RowIndex;//获取停留的行索引
string tip_tem="";
if (x != ei || y != i || str_tip != tip_tem)
{
this.toolTip1.Hide(this.datagv);
}
if (i >= 0 && ei >= 0)
{
if (x != ei || y != i || str_tip != tip_tem)//这里添加判断后还是闪烁???
{
Point mousePos = PointToClient(MousePosition);//获取鼠标当前的位置
string tip = this.datagv[i, ei].Value.ToString();//获取鼠标停留的单元格中的值
tip_tem = tip;
this.toolTip1.Show(tip, this.datagv, new Point(mousePos.X, ei * 35));//在指定位置显示提示框
toolTip1.Active= true;
x = ei;
y = i;
}
}
}
private void datagv_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
this.toolTip1.Hide(this.datagv);
}
#endregion