You can get the coordinates of the cursor using Cursor.Position , this will give you the screen coordinates. you can pass them to PointToClient(Point p)
Point screenCoords = Cursor.Position; Point controlRelatedCoords = this.panel1.PointToClient(screenCoords);
Although, I am sure that DragEventArgs.X and DragEventArgs.Y are already the coordinates of the screen. Your problem probably is
if (eX < 429 && eX > 0 && eY<430 && eY>0)
It looks like this will check the panel coordinates, while eX and eY are the screen coordinates at this point. Instead, before checking borders: turn them into panels,
Point screenCoords = Cursor.Position; Point controlRelatedCoords = this.panel1.PointToClient(screenCoords); if (controlRelatedCoords.X < 429 && controlRelatedCoords.X > 0 && controlRelatedCoords.Y < 430 && controlRelatedCoords.Y > 0) { }
source share