Mouse movement

  • Thread starter Thread starter Benjamin Vigneaux
  • Start date Start date
B

Benjamin Vigneaux

How can I keep track of the mouse movement?

for instance..

if ( mouse_moves_right ) { print_something }
else if ( mouse_moves_left ){ print_something_else }

many thanks in advance,

Benjamin.
 
Benjamin said:
How can I keep track of the mouse movement?

for instance..

if ( mouse_moves_right ) { print_something }
else if ( mouse_moves_left ){ print_something_else }

What kind of application are you developing, a Windows Forms
application, a Window Presentation Foundation application, or an ASP.NET
application?
 
It's a windows forms app

Martin Honnen said:
What kind of application are you developing, a Windows Forms application,
a Window Presentation Foundation application, or an ASP.NET application?
 
Benjamin Vigneaux said:
It's a windows forms app
Have you tried using the MouseMove event and putting code in a MouseMove
event procedure? You'll find MouseMove in the event list for just about and
of the available GUI components, including the form itself.
 
Benjamin said:
It's a windows forms app

Set up a MouseMove event handler for your Form control (or the form
where you want to check mouse movements) and store the last position and
compare to the actual position:

public partial class Form1 : Form
{
Point lastPos;
public Form1()
{
InitializeComponent();
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (lastPos != null)
{
if (lastPos.X < e.X)
{
Debug.WriteLine("Mouse moved right.");
}
else
{
Debug.WriteLine("Mouse moved left.");
}
}
lastPos = e.Location;
}
}
 
Back
Top