Reputation: 6776
So I am trying to move a pictureBox onto a panel. The problem is that the picturebox doesn't land on to the coordinate of the mouse but instead someplace else.
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
pictureBox1.DoDragDrop(pictureBox1,DragDropEffects.Copy);
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
pictureBox1.Location = new Point(e.X,e.Y);
}
What is wrong with my code?
Upvotes: 2
Views: 144
Reputation: 69392
e.X
and e.Y
represent screen coordinates and it seems you're looking for client coordinates.
pictureBox1.Location = panel1.PointToClient(new Point(e.X, e.Y));
Upvotes: 2