gpt4 book ai didi

c#: winforms: tooltip: 如何延迟 tooltip.Show

转载 作者:行者123 更新时间:2023-11-30 17:44:56 24 4
gpt4 key购买 nike

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

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

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

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

最佳答案

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

toolTip.InitialDelay = 5000;
toolTip.SetToolTip(dataGridView1, "Max InitialDelay is 5000 milliseconds");

注意:要使上述正常工作,请记住您首先必须禁用 DataGridView 内置工具提示:

dataGridView1.ShowCellToolTips = false;


EDIT:显示每行(和单元格)的工具提示。注意 CellMouseEnterCellMouseLeave 事件的使用

private ToolTip toolTip;

private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1 || e.ColumnIndex == -1) return;
var cell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];

if (cell.Value != null){
toolTip = new ToolTip();
toolTip.InitialDelay = 3000;
dataGridView1.ShowCellToolTips = false;
toolTip.SetToolTip(dataGridView1, cell.Value.ToString());
}
}

private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
if (toolTip != null)
toolTip.Dispose();
}

关于c#: winforms: tooltip: 如何延迟 tooltip.Show,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28764047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com