locked
Mouse movement RRS feed

  • Question

  •  Hello, how can I capture the right or left movement of the mouse?

    Friday, November 2, 2007 5:02 AM

Answers

  • when the mouse is over the element you want to know movement take the X coordinate to a variable. when mouse moves check current X coordinate if it is less than the previous its left movement orerwise right movement.

    double prevMposition=0;

     public void OnMouseEnter(object sender, MouseEventArgs e){

    prevMposition= e.GetPosition(null).X;

    }

    public void OnMouseMove(object sender, MouseEventArgs e)

    {

    mouseX = e.GetPosition(null).X;

    if(mouseX>prevMPosition) //right movement

    else //left movement

    prevMposition=mouseX;

    }

    Friday, November 2, 2007 6:07 AM

All replies

  • Call a function on MouseMove and then call CaptureMouse.

    Friday, November 2, 2007 5:10 AM
  • ok, but how can I understand if is a left or right movement?

    Friday, November 2, 2007 5:28 AM
  • when the mouse is over the element you want to know movement take the X coordinate to a variable. when mouse moves check current X coordinate if it is less than the previous its left movement orerwise right movement.

    double prevMposition=0;

     public void OnMouseEnter(object sender, MouseEventArgs e){

    prevMposition= e.GetPosition(null).X;

    }

    public void OnMouseMove(object sender, MouseEventArgs e)

    {

    mouseX = e.GetPosition(null).X;

    if(mouseX>prevMPosition) //right movement

    else //left movement

    prevMposition=mouseX;

    }

    Friday, November 2, 2007 6:07 AM
  • You will hate this answer, but you could track the last couple of x,y coordinates, and then calculate if its right or left by comparing the current X,Y to the previous.

    if Xlast - Xcurrent = a negative number you are moving right else you are moving left

    -Nirav
     

    Friday, November 2, 2007 6:12 AM
  • Thanks to all

    Friday, November 2, 2007 6:56 AM