【问题标题】:Don't hide Tooltip until remove mouse from the DataGridViewCell in Window Forms不要隐藏工具提示,直到从窗口窗体中的 DataGridViewCell 中移除鼠标
【发布时间】:2020-02-26 12:59:37
【问题描述】:

我必须显示 DataGridViewCell 的工具提示。 下面是这个的代码。

private void dgrSearch_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (e.ColumnIndex == 1 && e.RowIndex >= 0 && (e.ColumnIndex == this.dgrSearch.Columns["ID"].Index) && e.Value != null)
        {
            DataGridViewCell cell = this.dgrSearch.Rows[e.RowIndex].Cells[e.ColumnIndex];                
            string tooltip = this.dgrSearch.Rows[e.RowIndex].Cells["Description"].Value.ToString();
            cell.ToolTipText = tooltip;                
        }

    }

windows 中工具提示的默认行为是它会在一段时间后自动隐藏。但我的要求是,如果用户将鼠标悬停在单元格上,然后显示工具提示,直到鼠标悬停在该单元格上。

【问题讨论】:

  • 您可以禁用默认工具提示(因为您无法配置它)并自己提供一个。具有非常高的 AutoPopDelay 值的标准工具提示,InitialDelayReshowDelay 设置为 0ShowAlways = true(作为默认工具提示)。在 CellEnter 中,您可以将 ToolTip 设置为例如toolTip1.Show("Some Text", dataGridView1, dataGridView1.PointToClient(Cursor.Position)); 并将其隐藏在CellLeave 上。
  • 这可能会有所帮助:Show ToolTip for DataGridView on KeyDown。阅读答案下方的 cmets。
  • 您还可以找到DataGridView使用的ToolTip组件并对其进行操作。这可能会有所帮助:How to refresh tooltip of a DataGridView cell while it's shown?

标签: c# windows winforms tooltip


【解决方案1】:

这就是你想要做的 https://docs.microsoft.com/en-us/windows/win32/uxguide/ctrl-tooltips-and-infotips?redirectedfrom=MSDN#guidelines

适当的超时 提示的适当自动显示和删除对于用户保持对其 UI 环境的控制的目标至关重要。提示有三个超时值:

初始。指针必须保持静止以使笔尖移动的时间 出现。默认时间为 0.5 秒。

重播。指针必须保持静止的时间作为指针 从一个目标移动到另一个目标。默认时间为 0.1 秒。

删除。自动移除尖端的时间。这 默认时间为 5 秒。

初始值和重新显示值太短会导致令人讨厌的破坏性体验,因为它们经常会在不经意间显示出来,而太长会导致提示感觉迟钝或未被发现。默认删除时间适用于工具提示中使用的短提示文本。信息提示的文本较长,因此需要较长的显示时间。

【讨论】:

    猜你喜欢
    • 2011-05-25
    • 1970-01-01
    • 2010-09-29
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 2013-01-26
    • 1970-01-01
    • 2013-11-13
    相关资源
    最近更新 更多