Detect mouse leaving from a list view item

M

Mohit

Hi all,
I am working on a windows application with a list view on a form.
Now I wanted to show hand cursor when mouse is over list view item and
default(arrow) cursor at other places.

List view's ItemMouseHover event can tell me that mouse is on the
item and here I can change my cursor to hand. But I have no clue to
change it back to default cursor when mouse is moved out of the list
view item.

How can I detect that mouse is moved away/out of the list view
item??

I have also tried to use HitTest method of the list view in the
MouseMove event but it is causing lots of overhead and sometimes hangs
the application. So I am not using this option.
Can someone give me an idea how to achieve it.

Thanks!!
 
C

Ciaran O''Donnell

This seems to work fine for me. Never locks up. I dont know if you had an
issue with constantly setting the cursor. Thats why i check it before setting
it:

private void listView1_MouseMove(object sender, MouseEventArgs e)
{
if (listView1.HitTest(e.X, e.Y).Item == null && (this.Cursor !=
Cursors.Default))
{
this.Cursor = Cursors.Default;
}
else if (this.Cursor == Cursors.Default)
{
this.Cursor = Cursors.Hand;
}
}
 
M

Mohit

Hi,
Thanks Ciaran for your response.

Even after adding up cursor check it is still causing up to lots of
overhead and hanging up the application. CPU utilization clock is
showing up 100% usage when mouse is moved over the list view and
various items for a considerable amount of time.

Is there some other alternative exist??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top