Custom controls and events

J

jlea

I've created a custom control based on TreeView and it handles several
events, such as Mousedown. I added this custom control to the toolbox in
another project, dragged the custom control to the form and everything works
as it should with the custom control responding to the mousedown event.

I also want to respond to the mousedown down event occuring in the custom
control inside of the form containing the custom control. Does anyone know
how to let the custom control respond to the event and then allow it's
parent/owner to get to the event?

Thanks.

Jon.
 
A

Ajay Kalra

Instead of taking this approach where you depend upon parent/child
relationship, why not use events? Fire an event from the control and if
parent wants to handle it, it will provide the handler and it will get
called. This keeps the coupling loose between control and the parent
and is more flexible than the approach you mentioned.
 
R

Rachel Suddeth

If the event is public, you can handle it wherever you want. Just like an
event on any other control. Both event handlers will be run each time the
MouseDown even fires.
 
J

jlea

Thanks for the reply. I ended up creating a custom event passing information
along what I needed (a TreeNode) and that seemed to work very well. Can you
refire the mousedown event and then have the parent trap for the re-fired
mousedown event? It seems like that won't work since the control already has
a handler for the mousedown event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top