c#:winforms:工具提示:如何延迟工具提示。显示

c#:winforms:工具提示:如何延迟工具提示。显示,c#,winforms,datagridview,tooltip,C#,Winforms,Datagridview,Tooltip,我在DataGridView上使用winforms工具提示类(不是DataGridView的工具提示,因为我需要自定义格式。) 我在DataGridView的CellMouseEnter事件中调用toolTip.Show() toolTip.Show()立即显示工具提示,并且InitialDelay属性不起作用,因为我调用了toolTip.Show() 是否有另一种延迟toolTip.Show()的方法,就像常规的初始延迟一样。toolTip Show方法会立即显示工具提示文本,如果需要延迟,则

我在DataGridView上使用winforms工具提示类(不是DataGridView的工具提示,因为我需要自定义格式。)

我在DataGridView的CellMouseEnter事件中调用toolTip.Show()

toolTip.Show()立即显示工具提示,并且InitialDelay属性不起作用,因为我调用了toolTip.Show()

是否有另一种延迟toolTip.Show()的方法,就像常规的初始延迟一样。

toolTip Show方法会立即显示工具提示文本,如果需要延迟,则必须使用SetToolTip,最大延迟为5000毫秒:

toolTip.InitialDelay = 5000;
toolTip.SetToolTip(dataGridView1, "Max InitialDelay is 5000 milliseconds");  
注意:要使上述功能正常工作,请记住,首先必须禁用DataGridView内置工具提示:

dataGridView1.ShowCellToolTips = false;

编辑:显示每行(和单元格)的工具提示。 注意CellMouseEnter和CellMouseLeave事件的使用


我已经解决了我的问题;我在DataGridView CellMouseEnter事件中创建了工具提示的一个新实例,并在CellMouseLeave事件中释放了它

private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
    {
        // 
        // create and initilize toolTip1
        // 
        this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
        this.toolTip1.OwnerDraw = true;
        this.toolTip1.UseAnimation = false;
        this.toolTip1.UseFading = false;
        this.toolTip1.Draw += new System.Windows.Forms.DrawToolTipEventHandler(this.toolTip1_Draw);
        this.toolTip1.Popup += new System.Windows.Forms.PopupEventHandler(this.toolTip1_Popup);

        toolTip1.SetToolTip((DataGridView)sender, e.RowIndex.ToString() + " : " + e.ColumnIndex.ToString());
    }
}

private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
    {
        toolTip1.Dispose();
    }
}
但我不确定这是否是一个好的做法。我认为这对性能不好。因为我可以在用鼠标滚轮上下滚动datagridview时看到它,所以有些行似乎冻结了片刻,直到滚轮停止


如果有更好的解决方案,请提供建议

它不应该起作用。考虑设置单元格的TooTyPrimeType属性。@ HANSPASTANT,它应该通过将DeaGigIDVIEW中的SkyCeloToIP属性设置为false来工作,之后,TooTip组件可以用于其他控件;我将toolTip.Show更改为toolTip.SetTooltip。InitialDelay与其他控件一起工作正常,但对于datagridview来说有点复杂。由于SetTooltip的参数控件是DataGridView,因此当鼠标输入DataGirdViewCell时,它第一次起作用。但是当我将鼠标移动到另一个单元格时,新单元格的工具提示会立即显示(实际上我认为它根本不会消失,因为SetTooltip参数仍然是DataGridView而不是单元格)。ReshowDelay在这里也没用,因为它只在指针从一个控件移动到另一个控件(不在同一个控件中)时设置ReshowDelay。是否显示每个单元格的工具提示?我的意思是,不同的单元格有不同的文本?设计时的简单解决方案是:这对所有版本的VS都有效,包括VS2015
private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
    {
        // 
        // create and initilize toolTip1
        // 
        this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
        this.toolTip1.OwnerDraw = true;
        this.toolTip1.UseAnimation = false;
        this.toolTip1.UseFading = false;
        this.toolTip1.Draw += new System.Windows.Forms.DrawToolTipEventHandler(this.toolTip1_Draw);
        this.toolTip1.Popup += new System.Windows.Forms.PopupEventHandler(this.toolTip1_Popup);

        toolTip1.SetToolTip((DataGridView)sender, e.RowIndex.ToString() + " : " + e.ColumnIndex.ToString());
    }
}

private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
    if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
    {
        toolTip1.Dispose();
    }
}