开发者

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 ... ?


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


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.


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;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜