【发布时间】: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值的标准工具提示,InitialDelay和ReshowDelay设置为0和ShowAlways = 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