In a C# WFA I’ve been coding my own control that inherits from the System.Windows.Forms.Panel control. What I wanted to do is when the mouse is dragged within this panel (so basically mouse gets down while inside the panel and then mouse moves), I wanted to restrict the movement of the cursor to be only within this panel. So when the cursor hits the bounds of the panel, the movement should be restricted as to not get any further beyond the bounds.
I tried to write the code using the MouseDown, MouseUp, MouseMove events, manually checking the cursor position and adjusting it. When I tested it, I could visibly see the cursor go a tiny bit beyond the bounds and then return. What I’d like to do is for it to be smooth. So what I think is that I have to capture the moment when it’s been recognized that the mouse has been moved, but the cursor position has not been redrawn yet and do my correction there. When I searched, I found out this could possibly be done using some lower level operations with [DllImport(“user32.dll”)]. However, I’m not sure if that is not an overkill and if possible, I’d like to keep the solution as simple as possible. So my question is whether I made some error and this behavior can be achieved strictily via the controls’ events or whether I have to resort to some lower level operations.