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;