// pass in current control and its upper left screen location, and it will set up the mouse events args for you private void SetControlLocation(ref GLMouseEventArgs e, GLBaseControl cur) { // record control, bounds, and client location e.Control = cur; Point ctrlloc = cur.FindScreenCoords(new Point(0, 0)); // we need to find this each time, the control may have been dragged, can't cache it like previous goes at this code! e.Bounds = cur.Bounds; // in parent co-ords e.BoundsLocation = new Point(e.ScreenCoord.X - ctrlloc.X, e.ScreenCoord.Y - ctrlloc.Y); // to location in bounds e.Location = new Point(e.BoundsLocation.X - cur.ClientLeftMargin, e.BoundsLocation.Y - cur.ClientTopMargin); // to location in client rectangle co-ords // determine logical area if (e.Location.X < 0) { e.Area = GLMouseEventArgs.AreaType.Left; } else if (e.Location.X >= cur.ClientWidth) { if (e.Location.Y >= cur.ClientHeight) { e.Area = GLMouseEventArgs.AreaType.NWSE; } else { e.Area = GLMouseEventArgs.AreaType.Right; } } else if (e.Location.Y < 0) { e.Area = GLMouseEventArgs.AreaType.Top; } else if (e.Location.Y >= cur.ClientHeight) { e.Area = GLMouseEventArgs.AreaType.Bottom; } else { e.Area = GLMouseEventArgs.AreaType.Client; } // System.Diagnostics.Debug.WriteLine($"Pos {e.WindowLocation} VP {e.ViewportLocation} SC {e.ScreenCoord} BL {e.BoundsLocation} loc {e.Location} {e.Area} {cur.Name} {cur.Bounds}"); }