为什么Tooltip不显示?

时间:2012-09-14 22:26:18

标签: c# winforms datagridview tooltip

我在我的应用中添加了一个工具提示。

在我希望它显示提示/工具提示的控件(DataGridView)中,我在“Tooltip on”属性中添加了verbiage。但是我的措辞没有显示(确切地说没有任何内容)。

为什么?

我在一个相关的按钮上添加了措辞,它运行得很好。也许DGV本身无法处理工具提示?

以下是演示问题的完整示例

using System;
using System.Drawing;
using System.Windows.Forms;

static class Program
{
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        var form = new Form {
            Controls = {
                new Button { Name = "button", Location = new Point(10, 10) },
                new DataGridView { Name = "dgv", Location = new Point(10, 50) },
            },
        };

        var tooltip = new ToolTip();
        tooltip.SetToolTip(form.Controls["button"], "Button Tooltip");
        tooltip.SetToolTip(form.Controls["dgv"], "DGV Tooltip");

        Application.Run(form);
        GC.KeepAlive(tooltip); // it's cheaper than implementing IContainer on the form for this demo
    }
}

3 个答案:

答案 0 :(得分:7)

如果将datagridviews ShowCellToolTips设置为false,然后将常规工具提示控件添加到表单并设置文本值,它将显示它。

答案 1 :(得分:2)

您的帖子很难理解您想要的内容。我希望您需要DataGridView的工具提示,而不是每个单元格或行。

如果您想在控件上使用工具提示,而不是在单元格上,请尝试以下方法:

DataGridView.ShowCellToolTips = False

toolTip1.SetToolTip(DataGridView, "My DataGridView");

答案 2 :(得分:0)

我在这里找到答案:DataGridView ToolTipText not showing

private void dgvPlatypus_CellToolTipTextNeeded(object sender,   DataGridViewCellToolTipTextNeededEventArgs e)
{
    e.ToolTipText = "j. cutworm is a punk";
}
相关问题