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

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

问题描述

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

我在窗口中有一个画布.窗口是全屏的,但画布设置为窗口中心的 640x480 实心尺寸.我需要将鼠标位置放在画布内,而不是在窗口内.我该怎么做?

解决方案

这不行吗?

Point 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天全站免登陆