【问题标题】:Why is Tooltip not displaying?为什么工具提示不显示?
【发布时间】:2012-09-14 22:26:17
【问题描述】:

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

在我希望它显示提示/工具提示的控件(DataGridView)中,我在“Tooltip on”属性中添加了措辞。但是我的措辞没有显示(准确地说,什么都没有)。

为什么?

我向相关按钮添加了措辞,它工作得很好。也许 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
    }
}

【问题讨论】:

  • 你能展示如何添加的代码示例吗?
  • 这很容易复制。从这里复制和粘贴代码比将 DGV 和 ToolTip 拖放到表单上并设置 DGV 的扩展属性需要更长的时间。一个完全有效的问题。
  • 无代码 - 我只是删除了组件,并将文本输入到 DGV 的属性中。
  • 根据您的回答。 stackoverflow.com/questions/389439/… 的可能重复项

标签: c# winforms datagridview tooltip


【解决方案1】:

如果你将datagridviews ShowCellToolTips 设置为false,然后在表单中添加一个通用的工具提示控件并设置一个文本值,它将显示它。

【讨论】:

  • 看来你不能同时拥有 celltooltips 和一个通用的
  • 这为我解决了。 Marcus 是对的,如果 ShowCellToolTips 属性为 true(默认),您使用 ToolTip on <tooltip control name> 设计器属性设置的工具提示将不会显示。恕我直言,当 ShowCellToolTips 为真时,Visual Studio 应该隐藏 ToolTip on <tooltip control name>!
【解决方案2】:

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

如果您想在控件而不是单元格上显示工具提示,请尝试以下操作:

DataGridView.ShowCellToolTips = False

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

【讨论】:

  • 是的,你是对的——我只想在用户将鼠标悬停在 DGV 上时显示“提示”;正如我在上面添加的,它适用于按钮,但不适用于 DGV。
【解决方案3】:

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

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

【讨论】:

  • 因此解决方法是使用 DGV 中内置的每个单元格的工具提示。很好,但是问题是,“为什么你不能使用 ToolTip 控件获得一个单一的‘全局’工具提示?”徘徊。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-21
  • 2017-05-28
  • 1970-01-01
  • 2019-09-25
  • 1970-01-01
相关资源
最近更新 更多