使用C#在WPF应用程序中检查鼠标点 [英] Check Mouse Point in WPF application using C#
本文介绍了使用C#在WPF应用程序中检查鼠标点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我检查特定窗口中的控件吗?
详细地,
如何找到鼠标指针下方的内容,我可以获取鼠标指针(假设它在X& Y(200,400)中).如何找到该点(200,400)上除鼠标指针以外的其他东西,例如按钮,标签或面板?
我正在使用此代码来获取鼠标指针.
Can any one give help me to check what controls are in a specific point of window?
In detail,
How to find what is under the mouse pointer, I can get mouse point(let''s say it is in X & Y (200,400)). How do I can find what are the other things in that point(200,400) other than mouse pointer, like Button,Label or Panel?
I''m using this code to get mouse point.
void Form1_MouseDownDrawing(object sender, System.Windows.Input.MouseEventArgs e)
{
textBox1.Text = e.GetPosition(this).ToString();
}
private void Window_MouseDown(object sender,System.Windows.Input.MouseButtonEventArgs e)
{
this.MouseDown += new system.Windows.Input.MouseButtonEventHandler(Form1_MouseDownDrawing);
}
推荐答案
使用VisualTreeHelper.HitTest
.这是一篇有关使用此方法的文章:
简单,集成的WPF帮助系统 [
Use theVisualTreeHelper.HitTest
. Here is an article that talks about using this method:
A Simple, Integrated WPF Help System[^]
这篇关于使用C#在WPF应用程序中检查鼠标点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文