1

Possible Duplicate:
Handling a Click for all controls on a Form

I have a user control, I add controls on this user control. All of children will cover user control' region. That mean, you don't have any space to click on user control.

My problem how to detect user mouse click on this user control's region.

Please give me the best solution without add mouse click event handler on each child to detect mouse click. Thanks.

Community
  • 1
  • 1
Leo Vo
  • 9,980
  • 9
  • 56
  • 78
  • 2
    posible dublicate http://stackoverflow.com/questions/247946/handling-a-click-for-all-controls-on-a-form – Renatas M. Jun 09 '11 at 07:30
  • 1
    http://stackoverflow.com/questions/247946/handling-a-click-for-all-controls-on-a-form – VMAtm Jun 09 '11 at 07:36
  • Note: Mouse click event on user control will don't be raised because you are clicking on a its child. – Leo Vo Jun 09 '11 at 07:37

1 Answers1

2

As per you can do following

  1. handle control click event
  2. in that event check the sender -- its of your control type

This will do your task

For Example -- here I am handling button click event (you can handle click event of your control)

private void button1_Click(object sender, System.EventArgs e)
{
    if(sender is Button)//MyControl in you case 
    {
     //your code 
    }
}
Fenton
  • 241,084
  • 71
  • 387
  • 401
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263