A Problem With Object_OnMouseLeaveEx(obj)
Tuesday, August 7, 2007 by ARIrish- | Discussion: DesktopX
Sub Object_OnMouseLeaveEx(obj)
If SuspendAction = False Then
If Object.State = "AutoHide" Then
HidePanel
End If
End If
End Sub
This works just fine, BUT, the object is a background, or drawer, in which there are other objects. The problem is, when I move the mouse over one of these objects, DesktopX considers that a mouseleave and closes the drawer. Is there some way I can apply the 'OnMouseLeave' to a group of objects rather than just one?
Thanks.
Reply #2 Tuesday, August 7, 2007 9:38 PM
Thanks a lot
Much appreciated.Reply #3 Tuesday, August 7, 2007 9:48 PM
The easiest way to accomplish what you want will be using something like this:
- For Each elem In desktopx.GroupObjects("myGroup")
- If elem.visible=True Then
- elem.visible=False
- End If
- Next
Reply #4 Tuesday, August 7, 2007 10:15 PM
I've update my article with the For Each statement as that is much cleaner. (I've got to update my Script Helper now too!)
Reply #5 Tuesday, August 7, 2007 10:24 PM
Now if you mean there are two separate scripts than obviously there will be an override.
Here's a simple script using default objects I just did quickly. http://www.box.net/shared/imce9jlpfj
Reply #6 Tuesday, August 7, 2007 10:45 PM
Like this:
- Sub Object_OnMouseLeaveEx(obj)
- object.visible = False
- For Each elem In desktopx.GroupObjects("grpObj")
- If elem.visible=True Then
- elem.visible=False
- End If
- Next
- End Sub
- Sub Object_OnMouseEnterEx(obj)
- object.visible = True
- For Each elem In desktopx.GroupObjects("grpObj")
- If elem.visible=False Then
- elem.visible=True
- End If
- Next
- End Sub
Reply #7 Tuesday, August 7, 2007 11:32 PM
- Sub Object_OnMouseLeaveEx(obj)
- object.opacity= 1
- For Each elem In desktopx.GroupObjects("grpObj")
- If elem.visible=True Then
- elem.visible=False
- End If
- Next
- End Sub
- Sub Object_OnMouseEnterEx(obj)
- object.opacity= 100
- For Each elem In desktopx.GroupObjects("grpObj")
- If elem.visible=False Then
- elem.visible=True
- End If
- Next
- End Sub
Reply #9 Saturday, September 15, 2007 7:23 PM
The Ex functions receive events from all children of the parent containing it.
The obj variable contains the object reference which 'fired' the event.
So if you mouse_leaved a child called 'Child1' then obj.Name would be equal to "Child1"
I use this to tell the Ex function which objects to respond to.
The below uses 'Select obj.Name' to hide the parent object only for when the mouse leaves the parent object.
- Sub Object_OnMouseLeaveEx(obj)
- Select Case obj.Name
- Case Object.Name
- Object.Visible = False
- Case "child1"
- MsgBox("Your mouse has left child1")
- Case Else
- MsgBox("Your mouse has left a child object: "&obj.Name)
- End Select
- End Sub
You could add different responses for all the children objects by referring by name.
For example, to display a message box when you mouse leave the child objects called "child1".
You can use Case Else to cover for all 'other' children as well as in the above script too.

Reply #10 Sunday, October 21, 2007 9:24 PM
The only solution I've found, and sViz told me on another post he found the same, is to test if the mouse cursor is always inside the bounds of the parent object (in a rectangular manner), like this :
When that sub is trigerred by the entering of the mouse over a child object, its cursor is always in the rectangular bos of the parent object, so the result of the If...Then will be false and then the parent won't hide.
To go further, it's possible by this method to add a "margin" around the object, by setting it at the calculation of l,r,t & b, like that :
l = Object.Left - 5
r = Object.Right + 5
etc...
In this case, the parent object hides when the mouse leaves it PLUS a 5 pixels margin.
Bye...
Reply #11 Sunday, October 21, 2007 9:48 PM
Reply #12 Sunday, October 21, 2007 9:59 PM
So here it is :
Sub Object_OnMouseLeave ' Ex version is possible too
Dim x,y,l,r,t,b
x = System.CursorX
y = System.CursorY
l = Object.Left ' assuming the script is in the parent object
r = Object.Right
b = Object.Bottom
If x < l Or x > r Or y < t Or y > b Then
Object.Visible = False ' or anything the object is to do when mouse leaves
End If
End Sub
And of course, SirSmiley, it's good to place the test in a separate function, which returns a boolean, that's what I'm doing myself.
Reply #13 Monday, October 22, 2007 10:30 AM
To use the code blocks, all you really need to do is put your code within the tag:

Don't forget to define t
You shouldn't even need this test in there. Object_OnMouseLeave() will work with objects of any size/shape whereas your version will only work with rectangular objects.
Another thing to take note is that this callback will really only be triggered once, so if you're still within the bounding box of the object, it will stay visible even when moving your mouse off the object. (Of course if you're using a rectangular objects, this wouldn't be a concern.)
You could test this using the default circular DX object and then slowly moving your mouse off of it (I used 100% opacity on mouseenter and 50% opacity on script enter and on mouseleave when testing). The object will stay visible.
-Mike
[Stardock Support]
Reply #14 Monday, October 22, 2007 2:07 PM
For a more graphically complex container, I can't see a way... If someone knows how to get the alpha value of an object's pixel, let me know, because in this case, the test could be possible, and we can declare we're outside the object when the alpha at mouse's cursor is equal to zero.
Reply #15 Friday, November 2, 2007 10:38 PM
This way, whenever the appbar loses mouseover focus it will only hide if none of it's children are being mouseovered.
Example
Sub Object_OnMouseLeave
hide = True <--- a flag to tell the function whether or not to hide the appbar
For Each chld in Object.Children
If chld.State = "Mouse Over" Then
hide = False
Exit For
End If
Next
If hide = True then
'hide function
Else
'whatever/nothing
End If
End Sub
*Above has not been tested, just a theoretical script idea.
Reply #16 Monday, November 5, 2007 4:31 AM
Reply #18 Thursday, December 20, 2007 1:26 PM
What you can do is to make the mouseleave event start a timer, and a mouseover event for any of the children kills the timer - if the timer fires, it does the relevant hiding then kills itself.
This serves the dual purpose of providing a delay for the hiding to allow for accidental slips of the mouse.
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!







Reply #1 Tuesday, August 7, 2007 9:30 PM