开发者

How to capture mouse movements C# form application?

开发者 https://www.devze.com 2022-12-20 10:56 出处:网络
How to capture mouse movements C# form ap开发者_C百科plication?Here\'s a snippet: Point mouseLocation;

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
            }
0

精彩评论

暂无评论...
验证码 换一张
取 消