In Depth Banner
Skip Navigation Links

Select your preferred language

The MouseMove Handler. 

    private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

    {

      Graphics g=CreateGraphics();

      

      inborder = borderRegion.IsVisible(new Point(e.X,e.Y),g);

 

      g.Dispose();

 

      if(!moving & !sizing & !inborder)

      {

        if(closerPos==45)

        {

          opening=false;

          this.closer.Interval=2000;

          this.closer.Enabled=true;

        }

 

        inborder=false;

        Cursor=Cursors.Arrow;

 

        //Do non-border processing here...

        return;

      }

 

 

      if(!sizing)

      {

        

        if((e.Y<45 & e.X<45))

        {

          this.Cursor=Cursors.SizeNWSE;

          sizeAction=SizeAction.SizeTopLeft;

        }

        else if(e.Y>this.Height-45 & e.X>this.Width-45)

        {

          this.Cursor=Cursors.SizeNWSE;

          sizeAction=SizeAction.SizeBottomRight;

        }

        else if (e.Y<45 & e.X>this.Width-45)

        {

          if(closerPos!=45)

          {

            opening=true;

            this.timer1.Interval=10;

            this.timer1.Enabled=true;

          }

          this.Cursor=Cursors.SizeNESW;

          sizeAction=SizeAction.SizeTopRight;

        }

        else if(e.Y>this.Height-45 & e.X<45)

        {

          this.Cursor=Cursors.SizeNESW;

          sizeAction=SizeAction.SizeBottomLeft;

        }

        else if(e.X<45)

        {

          this.Cursor=Cursors.SizeWE;

          sizeAction=SizeAction.SizeLeft;

        }

        else if(e.X>this.Width-45)

        {

          this.Cursor=Cursors.SizeWE;

          sizeAction=SizeAction.SizeRight;

        }

        else if(e.Y>this.Height-45)

        {

          this.Cursor=Cursors.SizeNS;

          sizeAction=SizeAction.SizeBottom;

        }

        else if (e.Y<45)

        {

          this.Cursor=Cursors.SizeNS;

          sizeAction=SizeAction.SizeTop;

        }

      }

      

      if (sizing)

      {

        Point t,s,oldLoc;

        switch(sizeAction)

        {

          case SizeAction.SizeTop:

            this.Location=new Point(this.Location.X,this.Location.Y+e.Y);

            this.Size=new Size(this.Size.Width,this.Size.Height-e.Y);

            break;

          case SizeAction.SizeLeft:

            this.Location=new Point(this.Location.X+e.X,this.Location.Y);

            this.Size=new Size(this.Size.Width-e.X ,this.Size.Height);

            break;

          case SizeAction.SizeRight:

            this.Size=new Size(e.X,this.Size.Height);

            break;

          case SizeAction.SizeBottom:

            this.Size=new Size(this.Size.Width,e.Y);

            break;

          case SizeAction.SizeTopLeft:

            t=new Point(e.X-cursorOffset.X,e.Y-cursorOffset.Y);

            Location=this.PointToScreen(t);

            this.Size=new Size(this.Size.Width-t.X ,this.Size.Height-t.Y);

            break;

          case SizeAction.SizeBottomLeft:

            oldLoc=Location;

            t=new Point(e.X-cursorOffset.X,e.Y-cursorOffset.Y);

            s=this.PointToScreen(t);

            this.Location=new Point(s.X,Location.Y);

            this.Size=new Size(this.Size.Width-(Location.X-oldLoc.X) ,e.Y+(this.Height-cursorOffset.Y) );

            this.cursorOffset.Y=e.Y;

            break;

          case SizeAction.SizeTopRight:

            oldLoc=Location;

            t=new Point(e.X-cursorOffset.X,e.Y-cursorOffset.Y);

            s=this.PointToScreen(t);

            this.Location=new Point(Location.X,s.Y);

            this.Size=new Size(e.X+(this.Size.Width-cursorOffset.X),this.Size.Height-(Location.Y-oldLoc.Y));

            this.cursorOffset=new Point(e.X,cursorOffset.Y);

            break;

          case SizeAction.SizeBottomRight:

            this.Size=new Size(e.X+(this.Size.Width-cursorOffset.X),e.Y+(this.Size.Height-this.cursorOffset.Y));

            cursorOffset=new Point(e.X,e.Y);

            break;

        }

      }

 

      if (moving)

      {

        this.Cursor=Cursors.SizeAll;

        this.Location=PointToScreen(new Point(e.X-cursorOffset.X,e.Y-cursorOffset.Y));

      }

    }

 

Return to the article. 

Copyright © Bob Powell 2003-2009. All rights reserved