获取鼠标光标的定位时,点击出方形式的边界 [英] Getting Position of mouse cursor when clicked out side the form's boundary

查看:214
本文介绍了获取鼠标光标的定位时,点击出方形式的边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是很容易,只需dragaging鼠标发送多个值到表单当过位置的变化,形成了下面这行代码来获得光标出方形式的边界的位置。

It is very easy to get the position of cursor out side the form's boundary by just dragaging the mouse it sends many values to the form when ever the position changes, form the following line of code.

        MessageBox.Show(Cursor.Position.ToString());



MessageBox的显示鼠标的位置。

不过,我需要获得鼠标位置,当用户的点击出方形式的边界。
并非仅通过将鼠标。我使用的代码的下面一行做到这一点:

But I need to get the mouse position when user clicked out side the forms boundary. Not by just hovering the mouse. I used the following line of Code to do this:

    private void Form1_Deactivate(object sender, EventArgs e)
    {
        MessageBox.Show(Cursor.Position.ToString());
    }



我把 MessageBox.Show(Cursor.Position.ToString() ); 到表单停用事件。当用户点击这个事件绝对occures形式之外。但它也将在用户不点击外界错误的价值观,但使用的 ALT + TAB 组合键改变程序。
其实我有捕捉从第一次点击的位置开始的区域的屏幕截图。因此,我需要的光标的位置被点击的形式外时。
类似:

I placed MessageBox.Show(Cursor.Position.ToString()); into forms Deactivate event. When user click outside the form this event definitely occures. But it also sends wrong values when user does not click outside but changes the program by using ALT + TAB key combination. Actually I have to capture screen shot of the area starting from the position of first click. Therefore I need the position of the cursor when it is clicked outside the form. like:

推荐答案

您应该使用全局鼠标钩子逻辑来做到这一点。

You should use Global Mouse Hook logic to do this.

下面是一篇好文章,这将有助于你:在C# 处理全球鼠标和键盘钩子

Here is a good article that will help you: Processing Global Mouse and Keyboard Hooks in C#

这篇关于获取鼠标光标的定位时,点击出方形式的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆