2009-08-24 61 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