Skip to main content
 首页 » 编程设计

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

2024年02月24日18telwanggs

我有一个带有弹出控件的对话框,当控件悬停在控件上时会显示工具提示。但是,如果我关闭该框然后重新显示它,则不会有任何工具提示。这是我的代码的一部分。当表单加载为 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; 
} 

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