我是C#的全新工具,我希望在列表框中啓用工具提示。我的願望是能夠顯示一個不同的工具提示,這取決於列表框中的懸停項目(標準列表框的行爲是爲自己顯示一個單獨的工具提示,而不管它是什麼物品)...工具提示在列表框中的奇怪行爲
我設法寫下面的代碼:
private void MyInheritedListBox_MouseMove(object _sender, MouseEventArgs _event)
{
int itemIndex = -1;
itemIndex = this.IndexFromPoint(new Point(_event.X, _event.Y));
Console.WriteLine(_event.X.ToString() + " - " + _event.Y.ToString());
if (itemIndex >= 0 && itemIndex != currentHoveredIndex)
{
string l_sMyItemString = (string)this.Items[itemIndex];
MyToolTip.Show(l_sMyItemString, this);
currentHoveredIndex = itemIndex;
}
if (currentHoveredIndex == -1)
{
MyToolTip.Hide(this);
}
}
private void MyInheritedListBox_MouseLeave(object sender, EventArgs e)
{
currentHoveredIndex = -1;
}
我的問題是,第一次啓動應用程序時,它的工作就像一個魅力...當我移動鼠標,工具提示如下,並調整自身適應懸停在項。精細。
但玩了幾分鐘後(或幾秒鐘),或用鼠標光標離開列表框,再次進入列表框時,我沒有任何工具提示了......我玩了幾秒鐘,然後我再次得到一個,但工具提示沒有跟着光標了...我的第一個猜測是,這是一個「顯示」的行爲,但我無法設法找到如何糾正它...
你傢伙有什麼想法?
在此先感謝!
它是WPF/Silverlight的或WinForm的? – 2010-10-18 06:23:59
哦,是的,我的壞,它是Winform! – 2010-10-18 08:34:07