Winform中控件,鼠标坐标位置计算
Winform中获得鼠标位置的 (是鼠标到屏幕左上角的位置):
pt=Cursor.Position;
获得控件距屏幕位置(是控件到屏幕左上角位置)
PointToScreen(this.drawingPanel.Location
获得控件距离Form窗体位置:
this.drawingPanel.Location
这里需注意鼠标的位置是到屏幕左上角距离,而不是到Form窗体的距离,这里取部分代码截图
//滑动前鼠标距离Panel左上角位置距离SizeFscreenMouseToPanel=(Size)pt-(Size)PointToScreen(this.drawingPanel.Location);//滑动前鼠标距离panel左上角占比doublemouseInPanelXPercent=screenMouseToPanel.Width/this.drawingPanel.Width;doublemouseInPanelYPercent=screenMouseToPanel.Height/this.drawingPanel.Height;
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。