Colin,
First I would like to ask why, as most of the time if a form disappeared
when I accidentally moved the mouse off of it, I would probably uninstall
the software... ;-)
As you found if you move the mouse over a child control, the mouse is now
over the child control. What I would suggest is you handle the MouseEnter &
MouseLeave event for each of your child controls also. You can use
AddHandler & a loop over the Controls collection to attach all your
children's mouse events to a single handler. Remember that child controls
can have children, so you will need to make this recursive.
I would consider incrementing a counter on MouseEnter, decrementing the
counter on MouseLeave, when the count is zero I am off the form & children.
Normally derived controls/forms should override OnMouseLeave, however
because you want to track the children also, I would make the form use the
MouseLeave event instead of overriding OnMouseLeave.
I suspect there may be a windows hook you can use, but I have not used any
windows hooks.
You may also want to ask this "down the hall" in the
microsoft.public.dotnet.framework.windowsforms or
microsoft.public.dotnet.framework.windowsforms.con trols newsgroups.
Hope this helps
Jay
"Colin McGuire" <co***********@lycos.co.uk.spam> wrote in message
news:10****************@demeter.uk.clara.net...
Hi again NG, this question follows from a similar question that I have
thought through a bit more, and the next problem I encountered :(
Here is the issue clearly: if I have form1 with a button on it, and in my
form1 source-code I put the following code
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
Debug.WriteLine("OnMouseLeave")
MyBase.OnMouseLeave(e)
End Sub
then as I move my mouse cursor over the button, the VS IDE output/debug
window displays "OnMouseLeave". Also as I move the mouse cursor off the
form (over something else, possibly not even one of my applications), the
output/debug window also displays "OnMouseLeave".
What I am wanting to do is hide the form if the mouse cursor moves off it
(but not to one of the controls on the form).
My question is how on earth can this be achieved given that the MouseLeave
event is fired for both situations (I want to execute Me.Hide() only when
the mouse really moves off the form, not when it moves onto some of the
controls on the form). There is another event I should be overriding
rather than OnMouseLeave?
Colin