I have a function that sets the location of a certain textbox to the location of mouse cursor whenever the dragover event is called.
private void DGVLogicSimView_DragOver(object sender, DragEventArgs e)
{
txtBoxDragPoint.Visible = true;
txtBoxDragPoint.BackColor = Color.LightSkyBlue;
txtBoxDragPoint.Location = new Point(e.X, e.Y);
e.Effect = DragDropEffects.Copy;
}
The above event works perfectly when the form is maximized. However, when the form is not maximized and located somewhere random in the desktop, the txtbox location gets all messed up.
I believe it is returning the mouse location relative to the form, not the screen. What is the best solution for this?
Yes, that’s because the D+D events deliver the mouse position in screen coordinates, not in client coordinates. You’ll need to map the position relative to the textbox’ parent, like this: