'Call parent control click event c#

I developping one win-form application which having one custom control with one label and text box, and placed the custom control in one panel with docksytle as fill,

there is mouse click event for panel and custom control both, but when i click only custom control mouse click event is firing not the panel click event,

so anyone please let me know how to call the panel mouse click event.



Solution 1:[1]

Are you sure that you really need to invoke click of parent control? In general it would be, in my opinion, a code smell if you will do something like that - especially when it requires some strange constructions.

If you need to react in a same way when clicking on panel and on any child control inside the panel, it should be enough just to call the same method from two event handlers (that is from event handler of parent panel and event handler of child control. If you need, for example, mouse pointer location inside parent panel, you can easily calculate the position of mouse pointer using, for example, PointToScreen() and PointToClient() methods.

Solution 2:[2]

This is not a general solution, but maybe it's what you're looking for:

private void CustomControl_MouseClick(object sender, MouseEventArgs e)
{
    panel_MouseClick(sender, e);
}

private void panel_MouseClick(object sender, MouseEventArgs e)
{

}

Solution 3:[3]

Create Click Event for each control in panel and invoke the parent :

private void This_Click(object sender, EventArgs e)
{
    this.InvokeOnClick(this, null);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marcin Wieczorek
Solution 2 ispiro
Solution 3 Peter Csala