How do you call another control’s event, e.g.: call a control’s mouse enter event?
Put the code you want to run in a method and call that method. You can also call it from the mouse enter event if you eh so that its called from both places.
So if I have code in a label’s mouse enter event and I wished to fire the labels mouse enter event, what would the code look like?
In VB you would have something like
call Labelname Mouse_enter
Use a method within the target control which says
Thanks for the response Greg, but I am still not getting it. Since almost every control has a mouse enter event what would be the syntax to target a specific control’s mouse enter event. I tried
controlname.raiseevent.mouseEnter, but that does not compile, any clues.?
You cannot just call any random control’s events. If you need to call the code that happens to be in an event handler, then you instead put the code in a method and so it can be called from anywhere (including the original event handler). This is what Roger is describing.
A subclass of a control can call its own event handlers using RaiseEvent, which is what Greg is describing.
[quote=106455:@Chris Benton]So if I have code in a label’s mouse enter event and I wished to fire the labels mouse enter event, what would the code look like?
In VB you would have something like call Labelname Mouse_enter[/quote]
You would put the code in a method, perhaps called LabelUpdate. Then in the MouseEnter event handler you would call LabelUpdate. And if you want to call that code from elsewhere, you just call LabelUpdate.
Paul, thanks for the response. The reason I am asking about this is that I have a container control on a window that should close (the container control that is) when the mouse exit event is fired. The problem is that the mouse exit event on the container control mouse exit event is not firing and so I need to trigger the container control close method from another event in the code. Its just a workaround until the bug is (hopefully) squashed.
Tough to say without sample code or an example project. In a quick test here, the ContainerControl MouseExit event handler is working for me. I put
Me.Close it in and it closed the container when the mouse exited its area.
I just put a Container Control instance on a window, added to that instance a MouseExit event handler with beep into it, it fires fine.
Same thing if I add the event handler to the parent.
Something else maybe wrong in your code. Can you just try to place a beep in the beginning of the MouseExit event, or
System.debulog "Exit" so you can see if the event is firing ? You can see the debuglog messages by clicking the right hand side icon at the very bottom of the IDE.
EDIT - Wait … I see you asked a similar question in another thread about Web where it seemed the event fired fine. Am confused. Which platform are you referring to ? Web or desktop ? And is now the event firing, or are you still having problems ? Thanks for clarifying.