Click event does not work in custom control

Asked

Viewed 102 times

1

I created a button (Usercontrol), until then ok, but when I put an event Click in it, does not work, already tried with the event Mousedown, also did not work.
I don’t think this is it, but this button has a Label which fills all of it, punch the label is a component of the control. A print:

  • @vnbrs That would be Handler?

  • @vnbrs No... I thought just adding the event in control would already work

  • @vnbrs I did not treat the event later...

1 answer

4


The click event is not triggered when you click on the child elements. The UserControl.Click is triggered only by clicking on UserControl and not in the Label that counters it.

In his UserControl treat the clicks of the child elements so that the UserControl.Click be fired.

componente1.Click += new EventHandler(filho_Click);
componente2.Click += new EventHandler(filho_Click);
componente3.Click += new EventHandler(filho_Click);

and the event Handler:

private void filho_Click(object sender, System.EventArgs e) {
    this.OnClick(e);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.