It works fine for me: I pasted your code in, and handled a few events:
bool isDrag = false;
Rectangle theRectangle;
Point startPoint;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isDrag = true;
startPoint = ((Control)sender).PointToScreen(new Point(e.X, e.Y));
theRectangle = new Rectangle(startPoint.X, startPoint.Y, 0, 0);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isDrag)
{
ControlPaint.DrawReversibleFrame(theRectangle,
this.BackColor, FrameStyle.Dashed);
Point endPoint = ((Control)sender).PointToScreen(new Point(e.X, e.Y));
int width = endPoint.X - startPoint.X;
int height = endPoint.Y - startPoint.Y;
theRectangle = new Rectangle(startPoint.X,
startPoint.Y, width, height);
ControlPaint.DrawReversibleFrame(theRectangle,
this.BackColor, FrameStyle.Dashed);
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
isDrag = false;
}
The start and end corners are exactly where I expect.
Did you remember the PointToScreen in the MouseDown handler?