Form MouseLeave event [modified]
-
Hi All, I have 2 main Form classes - ParentForm and ChildForm in the same exe. ChildForm has a bunch of numeric up-down controls on it. I create an instance of ChildForm, set TopLevel = true and do SetParent with the ParentForm as the parent handle (doing this enables the non client area of ChildForm to stay highlighted when its selected). Now the problem is I need to know when the mouse has left the ChildForm entirely. The Leave event for the ChildForm is never fired. If we listen to the MouseLeave event it gets fired if the mouse hovers over any of the numeric controls and also when the mouse goes to the parent form. Is there any way I can differentiate between these 2 cases ? Also note that we need to cover the case where some other external application (say notepad or Task Manager with always on top as true) is positioned exactly above the child form and is clicked EDIT UPDATE : Thanks to all for the replies ! Have asked the same question on the MSDN Forums - http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/51e040a5-77f9-4b43-a462-1b5e3a13b90a/?prof=required[^] TIA
modified on Monday, April 11, 2011 12:00 PM
-
Hi All, I have 2 main Form classes - ParentForm and ChildForm in the same exe. ChildForm has a bunch of numeric up-down controls on it. I create an instance of ChildForm, set TopLevel = true and do SetParent with the ParentForm as the parent handle (doing this enables the non client area of ChildForm to stay highlighted when its selected). Now the problem is I need to know when the mouse has left the ChildForm entirely. The Leave event for the ChildForm is never fired. If we listen to the MouseLeave event it gets fired if the mouse hovers over any of the numeric controls and also when the mouse goes to the parent form. Is there any way I can differentiate between these 2 cases ? Also note that we need to cover the case where some other external application (say notepad or Task Manager with always on top as true) is positioned exactly above the child form and is clicked EDIT UPDATE : Thanks to all for the replies ! Have asked the same question on the MSDN Forums - http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/51e040a5-77f9-4b43-a462-1b5e3a13b90a/?prof=required[^] TIA
modified on Monday, April 11, 2011 12:00 PM
-
private void Form1\_MouseLeave(object sender, EventArgs e) { Point point = this.PointToClient(Cursor.Position); if (!this.ClientRectangle.Contains(point)) MessageBox.Show("Ding"); }
Hope that helps
"You get that on the big jobs."
Hi Rob, Thanks for the code snippet - it works perfectly when the mouse leaves the ChildForm and moves into the ParentForm ! Howeverm for the second casse i mentioned - "some other external application (say Task Manager with always on top as true) is positioned exactly above the child form and is clicked" , the Mouse Leave event on the ChildForm is not triggered. Is there some other event i need to be listening to for this ?
-
Hi Rob, Thanks for the code snippet - it works perfectly when the mouse leaves the ChildForm and moves into the ParentForm ! Howeverm for the second casse i mentioned - "some other external application (say Task Manager with always on top as true) is positioned exactly above the child form and is clicked" , the Mouse Leave event on the ChildForm is not triggered. Is there some other event i need to be listening to for this ?
I think it is hard to solve. And then your mouse could walk into a dropped-down menu or context menu too. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
Hi Rob, Thanks for the code snippet - it works perfectly when the mouse leaves the ChildForm and moves into the ParentForm ! Howeverm for the second casse i mentioned - "some other external application (say Task Manager with always on top as true) is positioned exactly above the child form and is clicked" , the Mouse Leave event on the ChildForm is not triggered. Is there some other event i need to be listening to for this ?
Hi TIA You could start playing around with the form's Deactivate event but it probably wont completely resolve your issue. Also I'm sure you, or someone else has a good argument to implement this but it is unusual behaviour and may confuse the user. Regards Rob
"You get that on the big jobs."
-
Hi All, I have 2 main Form classes - ParentForm and ChildForm in the same exe. ChildForm has a bunch of numeric up-down controls on it. I create an instance of ChildForm, set TopLevel = true and do SetParent with the ParentForm as the parent handle (doing this enables the non client area of ChildForm to stay highlighted when its selected). Now the problem is I need to know when the mouse has left the ChildForm entirely. The Leave event for the ChildForm is never fired. If we listen to the MouseLeave event it gets fired if the mouse hovers over any of the numeric controls and also when the mouse goes to the parent form. Is there any way I can differentiate between these 2 cases ? Also note that we need to cover the case where some other external application (say notepad or Task Manager with always on top as true) is positioned exactly above the child form and is clicked EDIT UPDATE : Thanks to all for the replies ! Have asked the same question on the MSDN Forums - http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/51e040a5-77f9-4b43-a462-1b5e3a13b90a/?prof=required[^] TIA
modified on Monday, April 11, 2011 12:00 PM
TyrionTheImp wrote:
Also note that we need to cover the case where some other external application
(say notepad or Task Manager with always on top as true) is positioned exactly above the child form and is clickedDo you instead want to handle the
Control.LostFocus
[^] event? /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
I think it is hard to solve. And then your mouse could walk into a dropped-down menu or context menu too. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
Hey Luc, Regarding the context menus and tool strip/main menus we can listen to their Activated events, so i don`t think that should be an issue :) The tricky part is to differentiate between my applications client area and other windows that may be place directly above it. In that case, MosueLeave gets fired and the even if the user hovers over the other window, the Cursor is still within the client area boundaries ! One would expect WinForms to provide some notifications for such a basic event but i haven`t (yet) found anything helpful in the Win32 API layer as well.
-
Hi TIA You could start playing around with the form's Deactivate event but it probably wont completely resolve your issue. Also I'm sure you, or someone else has a good argument to implement this but it is unusual behaviour and may confuse the user. Regards Rob
"You get that on the big jobs."
Hi Rob, Yes Deactivated would work when the user actually activates another window thus deactivates my window. However, the behavior i`ve described does not really seem unusual - for example if the user is working with my application - and the mouse enters/leaves the child windows and the parent window , then certain parts of the UI are highlighted accordingly - thus reducing user confusion :)
-
TyrionTheImp wrote:
Also note that we need to cover the case where some other external application
(say notepad or Task Manager with always on top as true) is positioned exactly above the child form and is clickedDo you instead want to handle the
Control.LostFocus
[^] event? /raviMy new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
Hey Ravi, Thanks for the reply - will try it in combination with the code suggested by Rob earlier.