Changing and flickering a ListView cursor

I am trying to change the cursor that appears in the standard ListView when the cursor appears above the item. However, I get a flickering effect when the mouse is changed to a finger pointer, and then back to what I asked.

I am trying to isolate this flicker / change on a hand cursor, but cannot figure out where it is happening or how to stop it. To reproduce this ...

1) Create a form with a ListView on it. 2) Add a list of images and some images. Set the view mode to a large icon. 3) Add some items to the ListView.

Add the MouseMove to the ListView :

 private void listView1_MouseMove(object sender, MouseEventArgs e) { ListViewItem selected = this.listView1.GetItemAt(eX, eY); if (selected == null) { base.Cursor = Cursors.Default; } else { base.Cursor = Cursors.No; } } 

Running an application, moving the mouse over an item. You should see that the cursor flickers between No (no entry cursor) and the finger pointer when you are above the element. The question is how to make sure that it simply displays a No cursor and does not flicker. (C # .NET).

I tried to override both OnMouseMove and OnMouseHover to return to ensure that they do not install anything. I also tried to override the Cursor property and say "only the default or no cursors", and that didn't work either.

Any help was appreciated.

Yang

+4
source share
2 answers

The problem is that C # ListView Control is basically a wrapper around the View View Control window. Therefore, when we position the cursor on an arrow, the main listview control always defaults to β€œManual,” while our parameter in the C # ListView class wanted it to be an arrow. That's why we got this flicker because basic control was coming back into our hands.

Here is the code you need to add:

 public const uint LVM_SETHOTCURSOR = 4158; [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); SendMessage(listView1.Handle, LVM_SETHOTCURSOR, IntPtr.Zero, Cursors.Arrow.Handle); 

It is very important that you call SendMessage from your FormLoad event, because by that time the main ListView control is fully initialized!

It's pretty simple, have a great time! :)

+7
source

Without trying, cursors usually change in response to WM_ SETCURSOR, so you may be in conflict with the default processing of WM_ SETCURSOR in a ListView. I would try to create a new UserControl retrieved from the ListView, and then catch WM_ SETCURSOR in WndProc and see if that helps.

0
source

All Articles