473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Form1: OnMouseLeave

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
Nov 20 '05 #1
3 1573
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

Nov 20 '05 #2
Hi Colin,

I very rarely counter Jay's advice, but Enter/Leave handlers for every
control shouldn't be necessary.

I would consider obtaining the mouse co-ordinates and determining whether
the mouse is still above your Form

In MouseLeave you could get the mouse co-ordinates and convert them to
screen co-ordinates. These could then be tested against the Form's Location
and Size. But!

I wouldn't do it this myself. As Jay suggests, a disappearing Form can be
disconcerting. I accept, however, that there are legitimate reasons and my
concern would be the User-friendliness within this scenario.

If I were to <accidently> move off a Form that I know is going to
disappear, I would be cursing the effort required to get it back, and be
thinking 'why couldn't it have just waited a liitle while'.

So that's what I would implement. Setting a Timer in MouseLeave (maybe
half a second) and getting the mouse co-ordinates in the Tick handler would do
the job. If the mouse is out, so goes the Form.

Your next question will be how do I get the mouse position such that I can
test it against the Form. I don't have the answer to that to hand so I'm just
posting the method for now. You may want to repost that as a separate question
(here and/or in the windowsforms groups that Jay gave you).

Regards,
Fergus
Nov 20 '05 #3
Fergus,
Ha! take the easy road!

I figured there was an easier method, all I was thinking was windows hook...

Thanks
Jay

"Fergus Cooney" <fi*****@post.com> wrote in message
news:uG**************@TK2MSFTNGP12.phx.gbl...
Hi Colin,

I very rarely counter Jay's advice, but Enter/Leave handlers for every
control shouldn't be necessary.

I would consider obtaining the mouse co-ordinates and determining whether the mouse is still above your Form

In MouseLeave you could get the mouse co-ordinates and convert them to
screen co-ordinates. These could then be tested against the Form's Location and Size. But!

I wouldn't do it this myself. As Jay suggests, a disappearing Form can be disconcerting. I accept, however, that there are legitimate reasons and my
concern would be the User-friendliness within this scenario.

If I were to <accidently> move off a Form that I know is going to
disappear, I would be cursing the effort required to get it back, and be
thinking 'why couldn't it have just waited a liitle while'.

So that's what I would implement. Setting a Timer in MouseLeave (maybe
half a second) and getting the mouse co-ordinates in the Tick handler would do the job. If the mouse is out, so goes the Form.

Your next question will be how do I get the mouse position such that I can test it against the Form. I don't have the answer to that to hand so I'm just posting the method for now. You may want to repost that as a separate question (here and/or in the windowsforms groups that Jay gave you).

Regards,
Fergus

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pavils Jurjans | last post by:
Hallo, I have entered some event handling hell... I want to mimic the functionality of IE5.5 onmouseenter and onmouseleave events, using DOM-standard onmouseover and onmouseout events. The...
3
by: polarz | last post by:
I'm having trouble getting items from different classes to display in my textBox. e.g. private void button2_Click(object sender, System.EventArgs e) { someData sd = new someData();...
2
by: Colin McGuire | last post by:
Hi, I have a child form - when the mouse is over the button on the parent form, I show the child form. When the mouse cursor is moved away from the button, I hide the child form. My child form...
8
by: Bob | last post by:
This is a bug that affects all controls, not just the ones that it's screwing up in my app. I really need a workaround. Anyone? Please? Before I regret letting my MSDN subscription run out and pay...
9
by: Giggle Girl | last post by:
I have a very simple "hover menu", which you can see at: http://s161149005.onlinehome.us/DEMOS/FF/HMENU/main/default.htm Once you "pop it up", I want it to disappear if you mouse away from it...
2
by: Thevercad | last post by:
i had come across a problem trying to find an equivalent for onmouseleave for the netscape browser. I happened to find a thread in here, discussing the same problem, but with no solutions in the end....
1
by: Carod | last post by:
Hi, I have a div which scrolls out onmouseover and in onmouseleave. Within the div, there's another div containing the text. Within the text there's a link, which when rolled over triggers the...
5
by: jaysonnward | last post by:
Hello All: I've recently been recreating some 'dropdown menus' for a website I manage. I'm writing all my event handlers into my .js file. I've got the coding to work in Firefox, but the...
1
by: dipalichavan82 | last post by:
I am working on sharepont application. In a webpart , i have a grid.I want, when i right click on , grid cell, a popup comes(div). it has three items, on click of which particular links open. When i...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.