c# - 工具提示不会显示第二次创建表单

标签 c# winforms tooltip

我有一个带有弹出控件的对话框,当控件悬停在控件上时会显示工具提示。但是,如果我关闭该框然后重新显示它,则不会有任何工具提示。这是我的代码的一部分。当表单加载为 null 时,我正在初始化 tooltipOn。我已经完成了跟踪,tooltip1.Show() 确实在第二次调用时被调用,它根本就没有显示。知道为什么吗?

private void Panel1_MouseMove(object sender, MouseEventArgs e)
{
    Control ctrl = null;

    if (sender == Panel1)
        ctrl = ((Control)sender).GetChildAtPoint(e.Location);
    else
        ctrl = (Control)sender;

    if (ctrl != null)
    {
        if (tooltipOn != ctrl)
        {
            toolTip1.Show(toolTip1.GetToolTip(ctrl), ctrl, ctrl.Width / 2, ctrl.Height / 2);
            tooltipOn = ctrl;
        }
    }
    else
    {
        toolTip1.Hide(this);
        tooltipOn = null;
    }
}

最佳答案

可能是因为您不能在两个不同的控件上两次显示工具提示?

在你的 if 语句中试试这个:

if (tooltipOn != ctrl)
{
    //your moving the tooltip to a different control, 
    //hide it from the other first.
    if (tooltipOn != null)
        toolTip1.Hide(tooltipOn);  

    toolTip1.Show(
        toolTip1.GetToolTip(ctrl), ctrl, ctrl.Width / 2, ctrl.Height / 2
    );

    tooltipOn = ctrl;
}

如果这不起作用,我会尝试完全新的一个完全不同的工具提示,以确保每个控件在事件期间都有自己的控件。

关于c# - 工具提示不会显示第二次创建表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1323227/

相关文章:

c# - 适用于所有操作的 ActionMethodSelectorAttribute?

c# - 有没有计算C#程序中功能点个数的工具?

c# - 如何在网络浏览器控件内重新加载网页?

c# - WindowsFormsHost 布局问题

c# - ToolStripItemCollection.AddRange 方法中的缺陷?

javascript - 自定义 highcharts 工具提示以显示日期时间

c# - .NET 中字节的文字后缀?

jquery - 如何防止CKEditor为其iframe设置标题?

animation - 在D3 js中将SVG坐标转换为页面坐标

c# - LINQ to SQL多对多关系Insert和Delete问题