How to capture mouse movements C# form application?
How to capture mouse movements C# form ap开发者_C百科plication?
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 ;)
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
}
精彩评论