Reputation: 53
How to capture mouse movements C# form application?
Upvotes: 5
Views: 4709
Reputation: 726
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
}
Upvotes: 0
Reputation: 19871
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 ;)
Upvotes: 8