Click event does not work in custom control

1

I created a button (UserControl), so far ok, but when I push a Click event on it, it does not work, I already tried with the MouseDown event, it also did not work. I do not think it's this, but this button has a Label that fills all of it, so the label is a component of the control. A print:

    
asked by anonymous 21.10.2017 / 21:17

1 answer

3

The click event does not fire when you click the child elements. The UserControl.Click is only fired by clicking on the UserControl and not on the Label that opposes it.

In your UserControl , treat the clicks of child elements so that UserControl.Click is triggered.

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);
}
    
21.10.2017 / 21:32