.net – C# WinForms UserControl Mouse Event Help

controlseventsnet

I have a custom control that I created for my project. In this control there are several child controls like a Label, a PictureBox, and a LinkLabel. Other then the LinkLabel, I want the mouse over event currently on the parent control and have the control respond to the mouse over. The background color changes when you hover over the control, but the background color doesn't change when over a child control; this is because there is no MouseEnter and MouseLeave events on the child control. I solved this issue by added the parent controls delegate methods to the child controls. The problem remains that the click event also is ignored over the child controls when I've subscribed to the click event on my parent control. I can subscribe to each individual child control, but how do I force the click event of the parent control? The term I've found by searching is Event Bubbling, but this seems to only apply to ASP.NET technologies and frameworks. Any suggestions?

Best Answer

Your description leads me to believe that you want both your child and your parent controls to respond to a click on the child control.

If I understand your question correctly, I'd suggest subscribing to your child controls' click events and, in those event handlers, calling some common method that manipulates the state of the parent UserControl in the manner that you desire (e.g., changing the background color).