我正在使用以下MouseMove
事件处理程序将文本文件内容显示为CheckedListBox上的工具提示,并且存在标记为每个checkedListBoxItem的文本文件对象。c#checked listbox MouseMove vs MouseHover事件处理程序
private void checkedListBox1_MouseMove(object sender, MouseEventArgs e)
{
int itemIndex = checkedListBox1.IndexFromPoint(new Point(e.X, e.Y));
if (itemIndex >= 0)
{
if (checkedListBox1.Items[itemIndex] != null)
{
TextFile tf = (TextFile)checkedListBox1.Items[itemIndex];
string subString = tf.JavaCode.Substring(0, 350);
toolTip1.ToolTipTitle = tf.FileInfo.FullName;
toolTip1.SetToolTip(checkedListBox1, subString + "\n... ... ...");
}
}
}
问题是,我的应用程序正在减速,因为checkedListBox上频繁的鼠标移动。
作为替代方案,我想,我应该使用MouseHover
事件及其处理程序。但我找不到我的musePointer当前在哪个checkedListBoxItem上。就像这样:
private void checkedListBox1_MouseHover(object sender, EventArgs e)
{
if (sender != null)
{
CheckedListBox chk = (CheckedListBox)sender;
int index = chk.SelectedIndex;
if (chk != null)
{
TextFile tf = (TextFile)chk.SelectedItem;
string subString = tf.FileText.Substring(0, 350);
toolTip1.ToolTipTitle = tf.FileInfo.FullName;
toolTip1.SetToolTip(checkedListBox1, subString + "\n... ... ...");
}
}
}
这里int index
将返回-1,chk.SelectedItem
将返回null
。
什么可以解决这类问题?
这只适用于证明MouseEventArgs事件参数的事件。它在MouseHover中不起作用。 – Ash 2009-10-11 07:09:08