日期:2014-05-18 浏览次数:20850 次
//鼠标拖动的虚框实现 private Point m_StartPoint; private Point m_LastPoint; protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); this.m_StartPoint = e.Location; m_LastPoint = this.m_StartPoint; } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); Point endPoint = e.Location; int l = m_LastPoint.X > this.m_StartPoint.X ? this.m_StartPoint.X : m_LastPoint.X; int t = m_LastPoint.Y > this.m_StartPoint.Y ? this.m_StartPoint.Y : m_LastPoint.Y; int r = m_LastPoint.X > this.m_StartPoint.X ? m_LastPoint.X : this.m_StartPoint.X; int b = m_LastPoint.Y > this.m_StartPoint.Y ? m_LastPoint.Y : this.m_StartPoint.Y; Rectangle rect = Rectangle.FromLTRB(l, t, r, b); ControlPaint.DrawReversibleFrame(this.RectangleToScreen(rect), SystemColors.Highlight, FrameStyle.Dashed); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.Button == MouseButtons.Left) { Point endPoint = e.Location; int l = m_LastPoint.X > this.m_StartPoint.X ? this.m_StartPoint.X : m_LastPoint.X; int t = m_LastPoint.Y > this.m_StartPoint.Y ? this.m_StartPoint.Y : m_LastPoint.Y; int r = m_LastPoint.X > this.m_StartPoint.X ? m_LastPoint.X : this.m_StartPoint.X; int b = m_LastPoint.Y > this.m_StartPoint.Y ? m_LastPoint.Y : this.m_StartPoint.Y; Rectangle rect = Rectangle.FromLTRB(l, t, r, b); ControlPaint.DrawReversibleFrame(this.RectangleToScreen(rect), SystemColors.Highlight, FrameStyle.Dashed); int _l = endPoint.X > this.m_StartPoint.X ? this.m_StartPoint.X : endPoint.X; int _t = endPoint.Y > this.m_StartPoint.Y ? this.m_StartPoint.Y : endPoint.Y; int _r = endPoint.X > this.m_StartPoint.X ? endPoint.X : this.m_StartPoint.X; int _b = endPoint.Y > this.m_StartPoint.Y ? endPoint.Y : this.m_StartPoint.Y; Rectangle _rect = Rectangle.FromLTRB(_l, _t, _r, _b); ControlPaint.DrawReversibleFrame(this.RectangleToScreen(_rect), SystemColors.Highlight, FrameStyle.Dashed); m_LastPoint = endPoint; } }
------解决方案--------------------
上面 说得很详细了,虚线筐就是用鼠标事件,draw一个矩形出来。然后不用的时候再重新画这个图片。