This question is related to another question of mine which can be found here can be found here. I wanted to move a PictureBox
within its parent container which
you can move the box unconditionally (no testing of the current location) and have a limitation for your new location:
int nx = Math.Min(Math.Max(pictureBoxPackageView.Left + (e.X -start.X),0),pictureBoxPackageView.Parent.Width-pictureBoxPackageView.Width);
int ny = Math.Min(Math.Max(pictureBoxPackageView.Top + (e.Y -start.Y),0),pictureBoxPackageView.Parent.Height-pictureBoxPackageView.Height);
pictureBoxPackageView.Location = new Point(nx,ny);
I think if you add the following code, it will move the item without snapping to the top as an option.
//- MouseDownLocation.X
//- MouseDownLocation.Y
int nx = Math.Min(Math.Max(label1.Left - MouseDownLocation.X + (e.X - start.X), 0), label1.Parent.Width - label1.Width);
int ny = Math.Min(Math.Max(label1.Top - MouseDownLocation.Y + (e.Y - start.Y), 0), label1.Parent.Height - label1.Height);