In Depth Banner
Skip Navigation Links

Select your preferred language

The snap code.

    protected MouseEventArgs MouseSnap(MouseEventArgs e)

    {

      int px, py;

 

      if(_snap)

      {

        px=(int)(((float)e.X/_snapX)+0.5f)*_snapX;

        py=(int)(((float)e.Y/_snapY)+0.5f)*_snapY;

      }

      else

      {

        px=e.X;

        py=e.Y;

      }

 

      MouseEventArgs t=new MouseEventArgs(e.Button,e.Clicks,px,py,e.Delta);

 

      return t;

    }

 

Note how the C# compiler is used to cast the values to and from Integers. The Visual basic version is not so compact.

Return to the article

Copyright © Bob Powell 2003-2009. All rights reserved