分享

C#鼠标拖动控件并绘制虚框介绍

 kingjae 2013-05-28

C#鼠标拖动控件并绘制虚框介绍

 
  • 摘要:本文介绍C#鼠标拖动控件并绘制虚框,并提供完整的源码供参考。

效果如下:

 
C#鼠标拖动控件并绘制虚框代码如下:
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);
}
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多