User Controls: Handling Events

Q

Quina

Hi there.

I have a problem regarding an user control in which I need some help.
This user control should behave like a Button. The problem is that the
user control has child controls that cover it's entire area. So, when
I click the user control (myButton) the envents are listned by it's
child controls and not by the parent.

Is anyway possible to make the childs ignore thier events in order to
them be handled by myButon?

Thank you in advance.

Quina
 
K

Kevin Spencer

Have the User Control subscribe to the events of the child controls, and
respond to them by raising its' own events.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Q

Quina

Hi Kevin,

Thank you for your answer. But I'm bit confused here... I've already
readed somewhere a solution like the one you seggested but the problem
is that I dont know how to do this.

Whoul you be kind enought to give a few hint on this one? (links where
I can find some additional help or, perhaps a bit of code)

Best regards,

Quina
 
S

sa

register all child control and main control to same handler.

e.g.

this.Click += new System.EventHandler(this.this_Click);
this.childContol1 += new System.EventHandler(this.this_Click);
this.childContol2 += new System.EventHandler(this.this_Click);
this.childContol3 += new System.EventHandler(this.this_Click);
this.childContol4 += new System.EventHandler(this.this_Click);
.....

Let me know if this doesn't solve you problem. There could be other
ways of doing this.

________________________
(e-mail address removed)
http://www.openwinforms.com/
OpenWinForms - open source windows forms and controls
 
D

Daniel Marohn

this.Click += new System.EventHandler(this.this_Click);
this.childContol1 += new System.EventHandler(this.this_Click);
this.childContol2 += new System.EventHandler(this.this_Click);
this.childContol3 += new System.EventHandler(this.this_Click);
this.childContol4 += new System.EventHandler(this.this_Click);

@quina: you can (recursiv) enumerate throgh all controls using x.controls to
add all handlers
@sa: Please post the alternative way. I would really like to know it other
possiblilitys to handle this

greets and thx
Daniel
 

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