2009-08-24 115 views
1

我有一个对话框,其中弹出了控件,当控件被隐藏在控件上时显示工具提示。但是,如果关闭该框然后重新显示它,则不会提示任何工具提示。这是我的代码的一部分。我正在初始化tooltipOn表单加载为null时。我已经做了一个跟踪和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; 
    } 
} 

回答

2

好的,所以......在解决了这个问题之后,对于将来发现这篇文章有用的任何人在下面发表。为什么这是必要的,超越了我。

变化

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

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

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

试试这个您如果语句中:

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; 
} 

如果不工作,我将完全尝试newing了一个完全不同的工具提示,使活动期间确保每个控制得到的自己。

+0

这确实管用!我仍然不确定究竟发生了什么。你能向我解释为什么代码在我的表单第一次显示时工作,但不是第二次? – novacara 2009-08-24 16:12:57

+0

其实你知道吗?这只适用于我第一次显示表单时没有关注控件的情况。 – novacara 2009-08-24 16:14:54

+0

我认为这与您尝试跨多个控件使用相同的工具提示有关。通常,每个控件都有自己的工具提示。然而,你这样做的方式只能创建一个工具提示(根据我的说法),然后将它移动到哪个控件的鼠标上方。 – Joseph 2009-08-24 16:37:35