软件编程
位置:首页>> 软件编程>> C#编程>> 解决C#获取鼠标相对当前窗口坐标的实现方法

解决C#获取鼠标相对当前窗口坐标的实现方法

  发布时间:2022-10-07 12:57:57 

标签:c#,获取鼠标坐标

在我们编写客户端应用程序时,经常要用到鼠标当前的位置。在C#winform中,可以用Control.MousePosition获得当前鼠标的坐标,使用PointToClient计算鼠标相对于某个控件的坐标,如下
Point screenPoint = Control.MousePosition;//鼠标相对于屏幕左上角的坐标
Point formPoint = this.PointToClient(Control.MousePosition);//鼠标相对于窗体左上角的坐标
Point contextMenuPoint = contextMenuStrip1.PointToClient(Control.MousePosition); //鼠标相对于contextMenuStrip1左上角的坐标

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com