tags:

views:

570

answers:

3

I have form with few buttons and I want to know what button is under cursor now.

P.S. Maybe it's duplicate, but I can't find answer to this question.

+2  A: 

What about defining an on-Mouse-over event in each button which assigns the sender button to a public variable of a button type

Radian
Actually I'ts not buttons, it's third-party plug-ins ;)
Poma
+6  A: 

Have a look at GetChildAtPoint. You will have to do some extra work if the controls are contained in a container, see Control.PointToClient

Philip Fourie
That's it! Thank you!
Poma
A: 

You could do it a number of ways:

  1. Listen to the MouseEnter event of your form's controls. The "sender" parameter will tell you what control raised the event.

  2. Obtain the cursor position using System.Windows.Forms.Cursor.Location and map it to your form's coordinates using Form.PointToClient(). You can then pass the point to Form.GetChildAtPoint() to find the control under that point.

Andrew

Andrew