首页 > Windows开发 > 详细

Winform中控件,鼠标坐标位置计算

时间:2017-06-20 13:15:55      阅读:337      评论:0      收藏:0      [点我收藏+]

Winform中获得鼠标位置的 (是鼠标到屏幕左上角的位置):

pt = Cursor.Position;

获得控件距屏幕位置(是控件到屏幕左上角位置)

PointToScreen(this.drawingPanel.Location

获得控件距离Form窗体位置:

this.drawingPanel.Location

这里需注意鼠标的位置是到屏幕左上角距离,而不是到Form窗体的距离,这里取部分代码截图

//滑动前鼠标距离Panel左上角位置距离                
SizeF screenMouseToPanel = (Size)pt - (Size)PointToScreen(this.drawingPanel.Location);
//滑动前鼠标距离panel左上角占比                
double mouseInPanelXPercent = screenMouseToPanel.Width / this.drawingPanel.Width;
double mouseInPanelYPercent = screenMouseToPanel.Height / this.drawingPanel.Height;


Winform中控件,鼠标坐标位置计算

原文:http://volvo9yue.blog.51cto.com/12265053/1940067

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!