Yanshof
Yanshof

Reputation: 9926

How to find the mouse position on runtime?

I wrote a UserControl that contains 8 Buttons.

I added this UserControl to my page - and now I want to:

  1. Catch the button click event - so I add the implementation of INotifyPropertyChanged to the userControl and in the click event I send event that will be catch by the page

  2. Find the exact position of the button that was clicked - the screen location on the page -

this is something that I can't find how to do.

Please help ... ?

Upvotes: 1

Views: 2140

Answers (3)

Venkatesh
Venkatesh

Reputation: 37

only way to get the mouse position at runtime is in a mouse event handler, by calling e.GetPosition() - where "e" is a MouseEventArgs

double point1 = e.GetPosition(bitmapCadView.UIElement).X;

double point2 = e.GetPosition(bitmapCadView.UIElement).Y;

Upvotes: 0

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93611

Create a custom event args (e.g. WhereWasIPressedArgs) containing the position information you require and add a custom event on your control

e.g. event EventHandler<WhereWasIPressedArgs> WhereWasIPressed;.

In your 8-button control use mouse position information to set the argument's position property and call your event.

For details on a generic way to get mouse position have a look at this link

Upvotes: 1

RobSiklos
RobSiklos

Reputation: 8849

The only way to get the mouse position at runtime is in a mouse event handler, by calling e.GetPosition() - where "e" is a MouseEventArgs.

Upvotes: 1

Related Questions