private Point downPoint;
private Rectangle downRectangle;
private Rectangle lastRectangle;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
downPoint = e.Location;
downRectangle =
new Rectangle(0, 0, ((Control)sender).Width, pictureBox1.Height);
downRectangle.Offset(((Control)sender).PointToScreen(new Point(0, 0)));
ControlPaint.DrawReversibleFrame(
downRectangle, Color.White, FrameStyle.Thick);
lastRectangle = downRectangle;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
ControlPaint.DrawReversibleFrame(
lastRectangle, Color.White, FrameStyle.Thick);
Rectangle rectangle = downRectangle;
rectangle.Offset(e.X - downPoint.X, e.Y - downPoint.Y);
ControlPaint.DrawReversibleFrame(
rectangle, Color.White, FrameStyle.Thick);
lastRectangle = rectangle;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
ControlPaint.DrawReversibleFrame(
lastRectangle, Color.White, FrameStyle.Thick);
pictureBox1.Location = new Point(
((Control)sender).Location.X + e.X - downPoint.X,
((Control)sender).Location.Y + e.Y - downPoint.Y);
}
本文来自Delphi之窗,原文地址:
http://www.52delphi.com/
转载于:https://www.cnblogs.com/davidgoo/archive/2010/05/27/1745400.html
相关资源:c#在pictureBox控件上绘制矩形框,鼠标点击可拖拽,伸缩