在c# winform的pictureBox控件上 
点下鼠标 然后拖动鼠标 出现一个虚拟的巨型框
当鼠标up 放松的时候 虚拟巨型消失。就好象在桌面上按下鼠标 拖动鼠标 放开鼠标 的效果一样

解决方案 »

  1.   

    使用ControlPaint.DrawReversibleFrame
      

  2.   

    在mousedown中建立Rubberband类的对象
    mousemove中调用该对象的ResizeTo
    在MouseUp中调用该对象的End public class Rubberband
    {
    protected Control parent;
    protected Rectangle rect = Rectangle.Empty; public Rubberband(Control theParent, Point theStartingPoint)
    {
    parent = theParent;
    parent.Capture = true;
    Cursor.Clip = parent.RectangleToScreen(parent.ClientRectangle);
    rect = new Rectangle(theStartingPoint.X, theStartingPoint.Y, 0, 0);
    } public void End()
    {
    Cursor.Clip = Rectangle.Empty;
    parent.Capture = false; // erase the rubberband
    Draw();
    rect = Rectangle.Empty;
    } public void ResizeTo(Point thePoint)
    {
    // erase the old rubberband
    Draw(); // get the new size of the rubberband
    rect.Width =  thePoint.X - rect.Left;
    rect.Height = thePoint.Y - rect.Top; // draw the new rubberband
    Draw();
    } public Rectangle Bounds()
    {
    // return a normalized rectangle, i.e. a rect
    // where (left <= right) and (top <= bottom)
    if ( (rect.Left > rect.Right) || (rect.Top > rect.Bottom) )
    {
    int left = Math.Min(rect.Left, rect.Right);
    int right = Math.Max(rect.Left, rect.Right);
    int top = Math.Min(rect.Top, rect.Bottom);
    int bottom = Math.Max(rect.Top, rect.Bottom);
    return Rectangle.FromLTRB(left, top, right, bottom);
    }
    return rect;
    } // Reversible drawing method
    // Calling theis method the first time draws the rubberband.
    // Calling it a second time with the same rect erases the rubberband
    protected void Draw()
    {
    Rectangle r = parent.RectangleToScreen(rect);
    ControlPaint.DrawReversibleFrame(r, Color.White, FrameStyle.Dashed);
    }
    }
      

  3.   

    下面这篇文章没仔细看,你有时间也可以看一下
    http://www.microsoft.com/china/MSDN/library/enterprisedevelopment/softwaredev/SDaskgui02172004.mspx
      

  4.   

    public class Rubberband
      {
        protected Control parent;
        protected Rectangle rect = Rectangle.Empty;    public Rubberband(Control theParent, Point theStartingPoint)
        {
          parent = theParent;
          parent.Capture = true;
          Cursor.Clip = parent.RectangleToScreen(parent.ClientRectangle);
          rect = new Rectangle(theStartingPoint.X, theStartingPoint.Y, 0, 0);
        }    public void End()
        {
          Cursor.Clip = Rectangle.Empty;
          parent.Capture = false;      // erase the rubberband
          Draw();
          rect = Rectangle.Empty;
        }    public void ResizeTo(Point thePoint)
        {
          // erase the old rubberband
          Draw();       // get the new size of the rubberband
          rect.Width =  thePoint.X - rect.Left;
          rect.Height = thePoint.Y - rect.Top;      // draw the new rubberband
          Draw();
        }    public Rectangle Bounds()
        {
          // return a normalized rectangle, i.e. a rect
          // where (left <= right) and (top <= bottom)
          if ( (rect.Left > rect.Right) || (rect.Top > rect.Bottom) )
          {
            int left = Math.Min(rect.Left, rect.Right);
            int right = Math.Max(rect.Left, rect.Right);
            int top = Math.Min(rect.Top, rect.Bottom);
            int bottom = Math.Max(rect.Top, rect.Bottom);
            return Rectangle.FromLTRB(left, top, right, bottom);
          }
          return rect;
        }    // Reversible drawing method
        // Calling theis method the first time draws the rubberband.
        // Calling it a second time with the same rect erases the rubberband
        protected void Draw()
        {
          Rectangle r = parent.RectangleToScreen(rect);
          ControlPaint.DrawReversibleFrame(r, Color.White, FrameStyle.Dashed);
        }
      }
      

  5.   

    面的那个类不是我写的,从树上抄的,在窗体的MouseMove,MouseDown,MouseUp加入一下代码即可
    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
    if (rubberband != null)
    rubberband.ResizeTo(new Point(e.X,e.Y));
    }
    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
    this.rubberband = new Rubberband(this,new Point(e.X,e.Y));

    }private void Form1_MouseUp(object sender,MouseEventArgs e)
    {
    if (rubberband != null)
    { rubberband.End();
    rubberband = null;

    }}