I am using the following MouseMove
event-handler to show the text-file content as a tooltip on CheckedListBox and there is a text-file object tagged to each checkedListBoxItem.
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... ... ...");
}
}
}
The problem is, my application is slowing down because of frequent mouse movements on the checkedListBox.
As an alternative, I thought, I should use MouseHover
event and its handler. But I could not find out which checkedListBoxItem my musePointer is currently on. Like this:
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... ... ...");
}
}
}
Here int index
is returning -1 and chk.SelectedItem
is returning null
.
What can be the solution of this type of problem?