2011-04-04 47 views
0

我有一個窗體與幾個級別的容器嵌套(選項卡控件,表格,面板)。最低級別的控件都有工具提示文本。工具提示有效(有些時候,但這是另一種蠕蟲)。我想添加一些代碼,將MDI父級的狀態欄文本更改爲與鼠標移過的任何控件的工具提示文本相同。如果我在表單上使用MouseMove,它會在窗體上拾取移動,但不會在任何子控件上移動。如果我使用MouseLeave,它只會將鼠標移動到最頂層的小孩(一個選項卡控件),而內部沒有任何東西。合併工具提示文本功能與狀態欄

我可能會遞歸遍歷所有的容器並添加MouseLeave處理程序,但似乎令人討厭。提示最簡單的方法來完成這一點,將不勝感激。謝謝。

回答

0

供參考,在這裏是在窗體的構造函數中執行我的非理想遞歸解決方案:

 Action<Control> mouseListen = null; 
     mouseListen = control => 
     { 
      string toolText = toolTip.GetToolTip(control); 
      if (toolText != "") 
      { 
       control.MouseEnter += (sender, args) => 
        { Program.MainForm.Status = toolText; }; 
       control.MouseLeave += (sender, args) => 
        { Program.MainForm.Status = Program.MainForm.DefaultStatus; }; 
      } 
      foreach (Control child in control.Controls) 
       mouseListen(child); 
     }; 
     mouseListen(this);