How to capture mouse movements C# form application?
Asked
Active
Viewed 4,675 times
2 Answers
8
Here's a snippet:
Point mouseLocation;
public Form1( )
{
InitializeComponent();
this.MouseMove += new MouseEventHandler(Form1_MouseMove);
}
void Form1_MouseMove(object sender , MouseEventArgs e)
{
mouseLocation = e.Location;
}
@AdriannStander gives 3 excellent links for research -- I simply like writing code snippets ;)

IAbstract
- 19,551
- 15
- 98
- 146
0
This one works for ALL controls within the form. NOT just the form itself!
....
InitializeComponent();
foreach (Control ctrl in this.Controls)
{
ctrl.MouseMove += new MouseEventHandler(globalMouseMove);
}
....
private void globalMouseMove(object sender, MouseEventArgs e)
{
//TODO
}

sam byte
- 697
- 9
- 11