700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > C# WinForm中 获得当前鼠标所在控件 或 将窗体中鼠标所在控件名显示在窗体标题上...

C# WinForm中 获得当前鼠标所在控件 或 将窗体中鼠标所在控件名显示在窗体标题上...

时间:2019-11-15 11:22:16

相关推荐

C# WinForm中 获得当前鼠标所在控件 或 将窗体中鼠标所在控件名显示在窗体标题上...

转:/**********************

* 课题:将窗体中鼠标所在控件名显示在窗体标题上

* 作者:ZAXX

* QQ : 94027486

* 本课题可简单扩展:获取屏幕上鼠标所在位置的窗口句柄与类名

**********************/

using System;

using System.Drawing;

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace Zaxx

{

public partial class MouseOnControl: Form

{

[DllImport("User32.dll")]

private static extern IntPtr WindowFromPoint(Point p);

Timer timer;

public MouseOnControl()

{

InitializeComponent();

timer = new Timer();

timer.Interval = 200;

timer.Enabled = true;

timer.Tick += new EventHandler(timer_Tick);

}

void timer_Tick(object sender, EventArgs e)

{

Point p = Cursor.Position;

IntPtr h = WindowFromPoint(p);

foreach (Control con in this.Controls)

if (con.Handle == h)

this.Text = con.Name;

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。