mouseEnter event

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I have a MouseEnter event for a listview that cover the whole form. I have it so when mouse is over the listview, it will activate the form. So that i can roll the mousewheel without clicking on the listview first. It works everytime during debug but it only works sometime after compile and run. Sometime it takes many time the mouse entering the form before the form is in focus. Why is that?
 
Maybe you can use the Activated event of form instead, and call listview.Select here?
 
but the problem is, the form isn't activating when i put my mouse over it. Sometime it takes 5 times, sometime even more of the mouse going over the form before it activates. In debug, it works everytime. I can see a row in the listview got selected, but i can also see the other window still have focus. It feels like the mouseEnter event is firing everytime but the .activate command isnt going thru everytime.
 
Last edited:
I thought you meant selecting the listview when form was activated. Activating the form that way can not be done, this is from documentation for SetForegroundWindow function (Windows)
An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user.
 
Well, the .activate does work sometime, maybe one out of 5-8 times after compiled and everytime during debug.
Even after i switched to Setforegroundwindow api, it give me simular result but a bit more often, maybe 1 out of 3-5 times.

I am just trying to use the mousewheel on the window without having to click it first to select it. So if its not going to work everytime, it defeat the purpose. Now i am having it in the mouseMove event and hope one of the event activate the window.
I tried using a while loop to setforegroundwindow until it is in the foreground but that never seem to work.
I also notice something strange. If i have VS opened, it works everytime. After i closed VS, it fail all the time.
 
Last edited:
i just notice, on pinvoke.net , it said setforegroundwindow doesnt always work on win7. ForceForegroundWindow seems to work.
 
Last edited:
Back
Top