在 KeyDown 上显示 DataGridView 的工具提示 [英] Show ToolTip for DataGridView on KeyDown

查看:36
本文介绍了在 KeyDown 上显示 DataGridView 的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I'm looking for a way to display some help when a key is pressed. I'm thinking the best option is ToolTip. But how can I get it so it shows instantly on KeyDown on a DataGridView? I have the ToolTip setup when KeyDownis pressed. However it doesn't show up for some reason. This is the code in my KeyDown event:

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

但是当我按下 Ctrl 时没有任何显示.

Yet nothing displays when I push down Ctrl.

推荐答案

You should set this.dataGridView1.ShowCellToolTips = false; using design or using code,然后你可以手动显示工具提示.

You should set this.dataGridView1.ShowCellToolTips = false; using designer or using code, then you can show a manual ToolTip.

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

注意:你应该在表单处理时处理一个ToolTip,所以最好从表单上的工具箱中删除一个ToolTip组件并使用它.这样你就不需要自己手动处理了.

Note: You should dispose a ToolTip when the form disposes, so it's better to drop a ToolTip component from toolbox on form and use it. This way you don't need to dispose it manually yourself.

这篇关于在 KeyDown 上显示 DataGridView 的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆