获取鼠标位置在画布(但不是在窗口)? [英] Get Mouse Position on Canvas (But NOT on window)?

查看:215
本文介绍了获取鼠标位置在画布(但不是在窗口)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF 4和vb.net 2010中有一个项目。



我在窗口中有一个画布。窗口是全屏的,但是画布在窗口中心设置为640x480。我需要获取鼠标位置在画布内,但不在窗口内。













 点p = Mouse.GetPosition(canvas); 




鼠标指针的位置是
指定的
元素与
元素的左上角为原点,



I have a project in WPF 4 and vb.net 2010.

I have a canvas inside a window. The window is full screen, but the canvas is set to a solid 640x480 in the center of the window. I need to get the mouse position inside of the canvas, but NOT inside of the window. How do I do this?

解决方案

Doesn't this work?

Point p = Mouse.GetPosition(canvas);

The position of the mouse pointer is calculated relative to the specified element with the upper-left corner of element being the point of origin,

这篇关于获取鼠标位置在画布(但不是在窗口)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆