【问题标题】:Show ToolTip for DataGridView on KeyDown在 KeyDown 上显示 DataGridView 的工具提示
【发布时间】:2017-01-07 03:21:42
【问题描述】:

所以我正在寻找一种在按下某个键时显示一些帮助的方法。我认为最好的选择是ToolTip。但是我怎样才能让它在KeyDown 上立即显示在DataGridView 上?当按下KeyDown 时,我有ToolTip 设置。但是由于某种原因它没有显示出来。这是我的KeyDown 事件中的代码:

if (e.Control)
{
    if(tt == null)
    {
        tt = new ToolTip();
        tt.InitialDelay = 0;
        tt.Active = true;
        tt.Show("Help Test", dataGridView1.FindForm());
    }           
}

当我按下 Ctrl 时,什么都没有显示。

【问题讨论】:

  • 您应该使用设计器或使用代码设置this.dataGridView1.ShowCellToolTips = false;,然后您可以显示手册ToolTip。同样ToolTip 的单个实例就足够了。将ToolTip 组件从工具箱中拖放到表单上并使用它。

标签: c# .net winforms datagridview tooltip


【解决方案1】:

您应该使用设计器或使用代码设置this.dataGridView1.ShowCellToolTips = false;,然后您可以显示手册ToolTip

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if(e.Control)
        toolTip1.Show("Some help", this.dataGridView1);
}

注意:您应该在表单处理时处理ToolTip,因此最好从工具箱中将ToolTip 组件拖放到表单上并使用它。这样你就不需要自己手动处理了。

【讨论】:

  • 您可以将工具提示设置为始终显示。然后您可以使用KeyUp 隐藏工具提示。
  • 它现在可以工作了 :) 谢谢。实际上,我不得不将它从显示更改为 datagridview 的 settooltip。然后在 keyup 上只是做了一个 tooltip.removeall() 来清除它。
  • 顺便说一句,作为另一种选择,您可以使用Help 类和这样的代码:if(e.Control) Help.ShowPopup(dataGridView1, "Some help", PointToScreen(dataGridView1.Location)); 这样按Control 键会弹出帮助,然后按鼠标或任何隐藏帮助弹出的键。您可能想看看一些主题here
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多