UserControl Events

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hello...

I've created User Control with several Controls on it...
now, every time wheb user of this "User Control" double clicks anywhere on
it, ia want "Double Click" event to be fired...
even if user double clicked on a control wich belongs to "User Control", how
do i do this... (the last part)
 
David,

You could easily do this. Basically, for any control that has a
DoubleClick event, you could register your control to catch it, and then
fire an event when you catch the event from somewhere else. You could use a
combination of reflection and the Controls collection to determine this.

However, if the control does not raise a double click event, then you
might miss out on some events. To get around this, you can have your
control implement IMessageFilter, and then call the static AddMessageFilter
method on the Application class. This will allow you to hook into the
windows message loop. Basically, what you want to do is take the windows
handle for the message and see if it is equal to the handle of your control,
or the window is a child window (calling the IsChild API function through
the P/Invoke layer). If it returns true, and the message is
WM_LBUTTONDBLCLK, then you can fire your event.

It should be noted that this can cause a performance degredation,
because of the call to AddMessageFilter. It is something that you will have
to measure for yourself.

Hope this helps.
 
Back
Top